added cache for types

This commit is contained in:
Patrick Alvin Alcala 2025-03-20 15:05:21 +08:00
parent bcf9823ffb
commit 5c4c8ceca9
8 changed files with 109 additions and 9 deletions

View file

@ -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/typelist/functions/cache_gettypelist.dart';
import 'package:pharmacy_mobile/functions/barcode_scan_function.dart';
import 'package:pharmacy_mobile/functions/checkresult_function.dart';
import 'package:pharmacy_mobile/tables/ref_categories.dart';
@ -59,19 +60,24 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
late String imageUrl = '';
Future<void> _getGenerics() async {
final cache = await cacheGetGenericList(context);
if (cache.isNotEmpty) {
_genericNameList = cache;
} else {
_genericNameList = await _refGenericNames.getList();
}
_genericNameList = await _refGenericNames.getList();
setState(() {
checkResult(context, _genericNameList, 'Generics');
});
}
Future<bool> _getGenericsCache() async {
final cache = await cacheGetGenericList(context);
if (cache.isNotEmpty) {
_genericNameList = cache;
return true;
} else {
return false;
}
}
Future<void> _getTypes() async {
_typeList = await _refTypes.getList();
setState(() {
@ -79,6 +85,17 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
});
}
Future<bool> _getTypesCache() async {
final cache = await cacheGetTypeList(context);
if (cache.isNotEmpty) {
_typeList = cache;
return true;
} else {
return false;
}
}
Future<void> _getManufacturer() async {
_manufacturerList = await _refManufacturer.getList();
setState(() {
@ -87,9 +104,13 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
}
void autoRun() async {
final generics = await _getGenericsCache();
final types = await _getTypesCache();
if (await InternetConnectionChecker.instance.hasConnection) {
await _getGenerics();
await _getTypes();
if (!generics) await _getGenerics();
if (!types) await _getTypes();
await _getManufacturer();
// final sample = await _refMedicines.getList2();