From f71cb964210237972c8b420186a515d2299ccca0 Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Thu, 30 Jan 2025 16:37:00 +0800 Subject: [PATCH] update --- lib/pages/add_generics.dart | 63 +++++++++++++-------- lib/pages/add_medicine.dart | 98 ++++++++++++++++++-------------- lib/pages/add_stock.dart | 110 ++++++++++++++++-------------------- pubspec.lock | 8 +++ pubspec.yaml | 1 + 5 files changed, 155 insertions(+), 125 deletions(-) diff --git a/lib/pages/add_generics.dart b/lib/pages/add_generics.dart index 9a4cc95..3126cf3 100644 --- a/lib/pages/add_generics.dart +++ b/lib/pages/add_generics.dart @@ -9,6 +9,7 @@ import 'package:pharmacy_mobile/widgets/input_widget.dart'; import 'package:pharmacy_mobile/widgets/page_background_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'; class AddGenericsPage extends StatefulWidget { const AddGenericsPage({super.key}); @@ -23,6 +24,7 @@ class AddGenericsPageState extends State { final _refGenericNames = RefGenericNames(); final _nameController = TextEditingController(); final _formKey = GlobalKey(); + bool _isVisible = false; late List _categoryList = []; late String _selectedCategory = ''; @@ -54,35 +56,50 @@ class AddGenericsPageState extends State { _categoryList = []; _selectedCategory = ''; _categoryUUID = ''; + _isVisible = false; super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( - body: PageBackgroundWidget( - child: Center( - child: Column( - children: [ - const Gap(120), - const TitleWidget(firstTextSize: 16, secondTextSize: 32), - const Gap(32), - const TextWidget(text: 'Add Generics'), - const Gap(16), - Form( - key: _formKey, - child: Column( - children: [ - InputWidget(label: 'Name', controller: _nameController), - const Gap(16), - DropDownWidget( - label: 'Category', list: _categoryList, listTitle: 'category_name', onChanged: _updateCategory), - const Gap(16), - ButtonWidget(text: 'Add', onPressed: saveGeneric) - ], - )) - ], - )), + 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(120), + const TitleWidget(firstTextSize: 16, secondTextSize: 32), + const Gap(32), + const TextWidget(text: 'Add Generics'), + const Gap(16), + Form( + key: _formKey, + child: Column( + children: [ + InputWidget(label: 'Name', controller: _nameController), + const Gap(16), + DropDownWidget( + label: 'Category', + list: _categoryList, + listTitle: 'category_name', + onChanged: _updateCategory), + const Gap(16), + ButtonWidget(text: 'Add', onPressed: saveGeneric) + ], + )) + ], + )), + ), ), ); } diff --git a/lib/pages/add_medicine.dart b/lib/pages/add_medicine.dart index 2415ac0..4ab391d 100644 --- a/lib/pages/add_medicine.dart +++ b/lib/pages/add_medicine.dart @@ -11,6 +11,7 @@ import 'package:pharmacy_mobile/widgets/input_widget.dart'; import 'package:pharmacy_mobile/widgets/page_background_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'; class AddMedicinePage extends StatefulWidget { const AddMedicinePage({super.key}); @@ -29,6 +30,7 @@ class AddMedicinePageState extends State { final _refMedicines = RefMedicines(); final _nameController = TextEditingController(); final FocusNode _focusNode = FocusNode(); + bool _isVisible = false; late List _genericNameList = []; late String _selectedGeneric = ''; @@ -95,48 +97,60 @@ class AddMedicinePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - body: PageBackgroundWidget( - child: Center( - child: Column( - children: [ - const Gap(120), - const TitleWidget(firstTextSize: 16, secondTextSize: 32), - const Gap(32), - const TextWidget(text: 'Add Medicine'), - const Gap(16), - Form( - key: _formKey, - child: Center( - child: Column( - children: [ - InputWidget(label: 'Name', controller: _nameController), - const Gap(16), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - DropDownWidget( - label: 'Generic Name', - list: _genericNameList, - listTitle: 'generic_name', - onChanged: _updateGeneric), - const Gap(8), - TextWidget(text: _selectedCategory, size: 18), - ], - ), - const Gap(16), - DropDownWidget(label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType), - const Gap(16), - DropDownWidget( - label: 'Manufactorer', - list: _manufactorerList, - listTitle: 'manufactorer_name', - onChanged: _updateManufactorer), - const Gap(16), - ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine) - ], - ), - )) - ], + body: VisibilityDetector( + key: Key('AddMedicinePage'), + onVisibilityChanged: (visibilityInfo) { + if (visibilityInfo.visibleFraction > 0.5 && !_isVisible) { + setState(() { + _isVisible = true; + autoRun(); + }); + } + }, + child: PageBackgroundWidget( + child: Center( + child: Column( + children: [ + const Gap(120), + const TitleWidget(firstTextSize: 16, secondTextSize: 32), + const Gap(32), + const TextWidget(text: 'Add Medicine'), + const Gap(16), + Form( + key: _formKey, + child: Center( + child: Column( + children: [ + InputWidget(label: 'Name', controller: _nameController), + const Gap(16), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + DropDownWidget( + label: 'Generic Name', + list: _genericNameList, + listTitle: 'generic_name', + onChanged: _updateGeneric), + const Gap(8), + TextWidget(text: _selectedCategory, size: 18), + ], + ), + const Gap(16), + DropDownWidget( + label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType), + const Gap(16), + DropDownWidget( + label: 'Manufactorer', + list: _manufactorerList, + listTitle: 'manufactorer_name', + onChanged: _updateManufactorer), + const Gap(16), + ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine) + ], + ), + )) + ], + ), ), ), ), diff --git a/lib/pages/add_stock.dart b/lib/pages/add_stock.dart index a1327f3..6d69bdb 100644 --- a/lib/pages/add_stock.dart +++ b/lib/pages/add_stock.dart @@ -1,8 +1,5 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; import 'package:gap/gap.dart'; -import 'package:google_fonts/google_fonts.dart'; import 'package:pharmacy_mobile/tables/ref_medicines.dart'; import 'package:pharmacy_mobile/tables/stocks.dart'; import 'package:pharmacy_mobile/widgets/button_widget.dart'; @@ -12,7 +9,9 @@ import 'package:pharmacy_mobile/widgets/input_widget.dart'; import 'package:pharmacy_mobile/widgets/page_background_widget.dart'; import 'package:pharmacy_mobile/widgets/text_widget.dart'; import 'package:pharmacy_mobile/widgets/title_widget.dart'; -import 'package:intl/intl.dart'; +import 'package:visibility_detector/visibility_detector.dart'; // Import this package + +// import 'package:intl/intl.dart'; class AddStockPage extends StatefulWidget { const AddStockPage({super.key}); @@ -28,11 +27,11 @@ class _AddStockPageState extends State { final _quantityController = TextEditingController(); final _dateController = TextEditingController(); final _stocks = Stocks(); - final _ref_medicines = RefMedicines(); late List _medicineList = []; late String _selectedMedicine = ''; late DateTime selectedDate = DateTime.now(); + bool _isVisible = false; void autoRun() async { _medicineList = await _refMedicines.getList(); @@ -42,29 +41,8 @@ class _AddStockPageState extends State { _selectedMedicine = medicine; } - // Future _selectDate(BuildContext context) async { - // final DateTime? picked = await showDatePicker( - // context: context, initialDate: selectedDate, firstDate: DateTime(2015, 8), lastDate: DateTime(2101)); - // if (picked != null && picked != selectedDate) { - // setState(() { - // selectedDate = picked; - // final DateFormat formatter = DateFormat('MMMM dd, yyyy'); - // _dateController.text = formatter.format(selectedDate); - // }); - // } - // } - - // void _saveMedicine() async { - // final medName = _nameController.text; - // final medGenericUUID = await _refGenericNames.getUUID(_selectedGeneric); - // final medTypeUUID = await _refTypes.getUUID(_selectedType); - // final medManufactorerUUID = await _refManufactorer.getUUID(_selectedManufactorer); - - // await _refMedicines.postMedicine(medName, medGenericUUID, medManufactorerUUID, medTypeUUID); - // } - void saveStock() async { - final stockNameUUID = await _ref_medicines.getUUID(_selectedMedicine); + final stockNameUUID = await _refMedicines.getUUID(_selectedMedicine); final stockQuantity = _quantityController.text; final stockExpiration = _dateController.text; @@ -84,46 +62,58 @@ class _AddStockPageState extends State { _selectedMedicine = ''; _quantityController.dispose(); _dateController.dispose(); + _isVisible = false; super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( - body: PageBackgroundWidget( - child: Center( - child: Column( - children: [ - const Gap(120), - const TitleWidget(firstTextSize: 16, secondTextSize: 32), - const Gap(32), - const TextWidget(text: 'Add Stock'), - const Gap(16), - Form( - key: _formKey, - child: Center( - child: Column( - children: [ - DropDownWidget( - label: 'Medicine Name', - list: _medicineList, - listTitle: 'medicine_name', - onChanged: _updateMedicine), - const Gap(16), - InputWidget(label: 'Quantity', controller: _quantityController), - const Gap(16), - DatePickerWidget( - label: 'Date Expiration', - controller: _dateController, - value: selectedDate, - ), - const Gap(16), - ButtonWidget(text: 'Add Stock', onPressed: saveStock) - ], + body: VisibilityDetector( + key: Key('AddStockPage'), + onVisibilityChanged: (visibilityInfo) { + if (visibilityInfo.visibleFraction > 0.5 && !_isVisible) { + setState(() { + _isVisible = true; + autoRun(); + }); + } + }, + child: PageBackgroundWidget( + child: Center( + child: Column( + children: [ + const Gap(120), + const TitleWidget(firstTextSize: 16, secondTextSize: 32), + const Gap(32), + const TextWidget(text: 'Add Stock'), + const Gap(16), + Form( + key: _formKey, + child: Center( + child: Column( + children: [ + DropDownWidget( + label: 'Medicine Name', + list: _medicineList, + listTitle: 'medicine_name', + onChanged: _updateMedicine), + const Gap(16), + InputWidget(label: 'Quantity', controller: _quantityController), + const Gap(16), + DatePickerWidget( + label: 'Date Expiration', + controller: _dateController, + value: selectedDate, + ), + const Gap(16), + ButtonWidget(text: 'Add Stock', onPressed: saveStock) + ], + ), ), - ), - ) - ], + ) + ], + ), ), ), ), diff --git a/pubspec.lock b/pubspec.lock index 004cb77..13d727d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -653,6 +653,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + visibility_detector: + dependency: "direct main" + description: + name: visibility_detector + sha256: dd5cc11e13494f432d15939c3aa8ae76844c42b723398643ce9addb88a5ed420 + url: "https://pub.dev" + source: hosted + version: "0.4.0+2" vm_service: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ce1cb5b..4f3c55e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,6 +21,7 @@ dependencies: uuid: ^4.5.1 bottom_picker: ^2.10.1 intl: ^0.20.2 + visibility_detector: ^0.4.0+2 dev_dependencies: flutter_test: