fix caching on add medicines
This commit is contained in:
parent
5c4c8ceca9
commit
518415aa4e
8 changed files with 116 additions and 26 deletions
|
|
@ -4,6 +4,7 @@ import 'package:gap/gap.dart';
|
|||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/genericlist/functions/cache_getgenericlist.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/functions/cache_getmanufacturerlist.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/functions/cache_gettypelist.dart';
|
||||
import 'package:pharmacy_mobile/functions/barcode_scan_function.dart';
|
||||
import 'package:pharmacy_mobile/functions/checkresult_function.dart';
|
||||
|
|
@ -72,6 +73,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
|
||||
if (cache.isNotEmpty) {
|
||||
_genericNameList = cache;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -90,6 +92,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
|
||||
if (cache.isNotEmpty) {
|
||||
_typeList = cache;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -103,27 +106,45 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
});
|
||||
}
|
||||
|
||||
Future<bool> _getManufacturerCache() async {
|
||||
final cache = await cacheGetManufacturerList(context);
|
||||
|
||||
if (cache.isNotEmpty) {
|
||||
_manufacturerList = cache;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
final generics = await _getGenericsCache();
|
||||
final types = await _getTypesCache();
|
||||
final manufacturers = await _getManufacturerCache();
|
||||
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
if (!generics) await _getGenerics();
|
||||
if (!types) await _getTypes();
|
||||
print('generics: $generics, types: $types, manufacturers: $manufacturers');
|
||||
|
||||
await _getManufacturer();
|
||||
if (!generics || !types || !manufacturers) {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
await _getGenerics();
|
||||
await _getTypes();
|
||||
await _getManufacturer();
|
||||
|
||||
// final sample = await _refMedicines.getList2();
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
// final sample = await _refMedicines.getList2();
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.push('/main');
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.push('/main');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue