This commit is contained in:
Patrick Alvin Alcala 2025-02-06 11:42:58 +08:00
parent 9598e17abb
commit 064814e165
3 changed files with 87 additions and 55 deletions

View file

@ -11,7 +11,6 @@ import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart'; import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart'; import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:pharmacy_mobile/widgets/title_widget.dart'; import 'package:pharmacy_mobile/widgets/title_widget.dart';
import 'package:visibility_detector/visibility_detector.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
class AddGenericsPage extends StatefulWidget { class AddGenericsPage extends StatefulWidget {
@ -22,20 +21,59 @@ class AddGenericsPage extends StatefulWidget {
} }
class _AddGenericsPageState extends State<AddGenericsPage> { class _AddGenericsPageState extends State<AddGenericsPage> {
// final _formKey = GlobalKey<FormState>();
final _refCategories = RefCategories(); final _refCategories = RefCategories();
final _refGenericNames = RefGenericNames(); final _refGenericNames = RefGenericNames();
final _nameController = TextEditingController(); final _nameController = TextEditingController();
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
bool _isVisible = false; // bool _isVisible = false;
bool _isLoading = false; bool _isLoading = false;
late List _categoryList = []; late List _categoryList = [];
late String _selectedCategory = ''; late String _selectedCategory = '';
late String _categoryUUID = ''; late String _categoryUUID = '';
void autoRun() async { void _getList() async {
// if (await InternetConnectionChecker.instance.hasConnection) {
_categoryList = await _refCategories.getList(); _categoryList = await _refCategories.getList();
if (_categoryList.isEmpty) {
if (mounted) {
showNotification(context, 'Error: Empty', false);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
context.push('/main');
}
});
}
}
// } else {
// if (mounted) {
// showNotification(context, 'Error: No Internet Connection', false);
// WidgetsBinding.instance.addPostFrameCallback((_) {
// if (mounted) {
// context.push('/main');
// }
// });
// }
// }
}
void autoRun() async {
if (await InternetConnectionChecker.instance.hasConnection) {
_categoryList = await _refCategories.getList();
} else {
if (mounted) {
showNotification(context, 'Error: No Internet Connection', false);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
context.push('/main');
}
});
}
}
} }
void _updateCategory(dynamic category) { void _updateCategory(dynamic category) {
@ -76,7 +114,7 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
@override @override
void initState() { void initState() {
autoRun(); // autoRun();
super.initState(); super.initState();
} }
@ -86,7 +124,6 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
_categoryList = []; _categoryList = [];
_selectedCategory = ''; _selectedCategory = '';
_categoryUUID = ''; _categoryUUID = '';
_isVisible = false;
_isLoading = false; _isLoading = false;
super.dispose(); super.dispose();
} }
@ -94,49 +131,41 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: VisibilityDetector( body: PageBackgroundWidget(
key: Key('AddGenericsPage'), child: Center(
onVisibilityChanged: (visibilityInfo) { child: Column(
if (visibilityInfo.visibleFraction > 0.5 && !_isVisible) { children: [
setState(() { const Gap(96),
_isVisible = true; const TitleWidget(firstTextSize: 20, secondTextSize: 32),
autoRun(); const Gap(32),
}); const TextWidget(text: 'Add Generics'),
} const Gap(16),
}, FormBorderWidget(
child: PageBackgroundWidget( color: 'blue',
child: Center( child: Form(
child: Column( key: _formKey,
children: [ child: Column(
const Gap(96), children: [
const TitleWidget(firstTextSize: 20, secondTextSize: 32), InputWidget(label: 'Name', controller: _nameController),
const Gap(32), const Gap(16),
const TextWidget(text: 'Add Generics'), GestureDetector(
const Gap(16), onTap: _getList,
FormBorderWidget( child: DropDownWidget(
color: 'blue',
child: Form(
key: _formKey,
child: Column(
children: [
InputWidget(label: 'Name', controller: _nameController),
const Gap(16),
DropDownWidget(
label: 'Category', label: 'Category',
list: _categoryList, list: _categoryList,
listTitle: 'category_name', listTitle: 'category_name',
onChanged: _updateCategory), onChanged: _updateCategory),
const Gap(32), ),
if (_isLoading) const Gap(32),
Center(child: CircularProgressIndicator(color: Colors.white)) if (_isLoading)
else Center(child: CircularProgressIndicator(color: Colors.white))
ButtonWidget(text: 'Add', onPressed: saveGeneric) else
], ButtonWidget(text: 'Add', onPressed: saveGeneric)
)), ],
) )),
], )
)), ],
), )),
), ),
); );
} }

View file

@ -31,7 +31,7 @@ class DropDownWidget extends StatelessWidget {
const Gap(8), const Gap(8),
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), // Set the desired border radius borderRadius: BorderRadius.circular(12), // Set the desired border radius
border: Border.all(color: Colors.white), // Set the border color border: Border.all(color: Colors.white), // Set the border color
), ),
child: DropdownMenu( child: DropdownMenu(
@ -39,19 +39,22 @@ class DropDownWidget extends StatelessWidget {
dropdownMenuEntries: [ dropdownMenuEntries: [
for (var item in list) for (var item in list)
DropdownMenuEntry( DropdownMenuEntry(
label: item[listTitle].toString(), label: item[listTitle].toString(),
value: item[listTitle], value: item[listTitle],
) style: ButtonStyle(
foregroundColor: WidgetStateProperty.all<Color>(Colors.white),
textStyle: WidgetStateProperty.all<TextStyle>(
GoogleFonts.outfit(fontSize: 16, fontWeight: FontWeight.w500)))),
], ],
onSelected: onChanged, onSelected: onChanged,
width: MediaQuery.of(context).size.width * 0.8, width: MediaQuery.of(context).size.width * 0.8,
menuHeight: MediaQuery.of(context).size.width * 0.9, menuHeight: MediaQuery.of(context).size.height * 0.8,
textStyle: GoogleFonts.outfit(textStyle: TextStyle(color: Colors.white)), textStyle: GoogleFonts.outfit(textStyle: TextStyle(color: Colors.white)),
menuStyle: MenuStyle( menuStyle: MenuStyle(
backgroundColor: WidgetStateProperty.all<Color>(const Color.fromRGBO(13, 84, 106, 0.7)), backgroundColor: WidgetStateProperty.all<Color>(const Color.fromRGBO(23, 37, 62, 0.8)),
padding: WidgetStateProperty.all(const EdgeInsets.symmetric(vertical: 8.0)), padding: WidgetStateProperty.all(const EdgeInsets.symmetric(vertical: 16)),
shape: WidgetStateProperty.all(RoundedRectangleBorder( shape: WidgetStateProperty.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12), // Set the border radius for the dropdown menu borderRadius: BorderRadius.circular(20), // Set the border radius for the dropdown menu
)), )),
), ),
), ),

View file

@ -31,8 +31,8 @@ class PageBackgroundWidget extends StatelessWidget {
gradient: const RadialGradient( gradient: const RadialGradient(
tileMode: TileMode.clamp, tileMode: TileMode.clamp,
colors: [ colors: [
Color.fromRGBO(45, 15, 43, 1), Color.fromRGBO(26, 8, 25, 1),
Color.fromRGBO(77, 29, 73, 1), Color.fromRGBO(60, 22, 57, 1),
], ],
), ),
), ),