update
This commit is contained in:
parent
87d8bb483e
commit
17a1430ef0
11 changed files with 271 additions and 25 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_manufactorers.dart';
|
||||
|
|
@ -10,6 +11,7 @@ import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
|
|||
import 'package:pharmacy_mobile/widgets/form_border_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
||||
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';
|
||||
|
|
@ -32,6 +34,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final _nameController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
bool _isVisible = false;
|
||||
bool _isLoading = false;
|
||||
|
||||
late List _genericNameList = [];
|
||||
late String _selectedGeneric = '';
|
||||
|
|
@ -42,9 +45,15 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
late String _selectedManufactorer = '';
|
||||
|
||||
void autoRun() async {
|
||||
_genericNameList = await _refGenericNames.getList();
|
||||
_typeList = await _refTypes.getList();
|
||||
_manufactorerList = await _refManufactorer.getList();
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
_genericNameList = await _refGenericNames.getList();
|
||||
_typeList = await _refTypes.getList();
|
||||
_manufactorerList = await _refManufactorer.getList();
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _updateGeneric(dynamic generic) async {
|
||||
|
|
@ -52,9 +61,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final catuuid = await _refGenericNames.getCategoryUUID(_selectedGeneric);
|
||||
final catname = await _refCategories.getName(catuuid);
|
||||
|
||||
setState(() {
|
||||
_selectedCategory = catname;
|
||||
});
|
||||
setState(() => _selectedCategory = catname);
|
||||
}
|
||||
|
||||
void _updateType(dynamic type) {
|
||||
|
|
@ -66,12 +73,28 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
}
|
||||
|
||||
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);
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
await _refMedicines.postMedicine(medName, medGenericUUID, medManufactorerUUID, medTypeUUID);
|
||||
try {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
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);
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: $e', false);
|
||||
}
|
||||
} finally {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -147,8 +170,11 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
list: _manufactorerList,
|
||||
listTitle: 'manufactorer_name',
|
||||
onChanged: _updateManufactorer),
|
||||
const Gap(16),
|
||||
ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
|
||||
const Gap(32),
|
||||
if (_isLoading)
|
||||
Center(child: CircularProgressIndicator(color: Colors.white))
|
||||
else
|
||||
ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
|
||||
],
|
||||
),
|
||||
)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue