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

View file

@ -31,7 +31,7 @@ class DropDownWidget extends StatelessWidget {
const Gap(8),
Container(
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
),
child: DropdownMenu(
@ -39,19 +39,22 @@ class DropDownWidget extends StatelessWidget {
dropdownMenuEntries: [
for (var item in list)
DropdownMenuEntry(
label: item[listTitle].toString(),
value: item[listTitle],
)
label: item[listTitle].toString(),
value: item[listTitle],
style: ButtonStyle(
foregroundColor: WidgetStateProperty.all<Color>(Colors.white),
textStyle: WidgetStateProperty.all<TextStyle>(
GoogleFonts.outfit(fontSize: 16, fontWeight: FontWeight.w500)))),
],
onSelected: onChanged,
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)),
menuStyle: MenuStyle(
backgroundColor: WidgetStateProperty.all<Color>(const Color.fromRGBO(13, 84, 106, 0.7)),
padding: WidgetStateProperty.all(const EdgeInsets.symmetric(vertical: 8.0)),
backgroundColor: WidgetStateProperty.all<Color>(const Color.fromRGBO(23, 37, 62, 0.8)),
padding: WidgetStateProperty.all(const EdgeInsets.symmetric(vertical: 16)),
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(
tileMode: TileMode.clamp,
colors: [
Color.fromRGBO(45, 15, 43, 1),
Color.fromRGBO(77, 29, 73, 1),
Color.fromRGBO(26, 8, 25, 1),
Color.fromRGBO(60, 22, 57, 1),
],
),
),