fix cache error

This commit is contained in:
Patrick Alvin Alcala 2025-04-22 17:34:38 +08:00
parent 6bdc9a7c6c
commit 0561d9a9b4
3 changed files with 112 additions and 41 deletions

View file

@ -3,8 +3,10 @@ import 'package:flutter/material.dart';
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/distributorlist/functions/cache_getdistributorlist.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/supplierlist/functions/cache_getsupplierlist.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';
@ -129,7 +131,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
});
}
Future<bool> _getManufacturerCache() async {
Future<bool> _getManufacturersCache() async {
final cache = await cacheGetManufacturerList(context);
if (cache.isNotEmpty) {
@ -141,51 +143,84 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
}
}
void autoRun() async {
// final generics = await _getGenericsCache();
// final types = await _getTypesCache();
// final manufacturers = await _getManufacturerCache();
Future<bool> _getDistributorsCache() async {
final cache = await cacheGetDistributorList(context);
// if (!generics || !types || !manufacturers) {
// if (await InternetConnectionChecker.instance.hasConnection) {
// await _getGenerics();
// await _getTypes();
// await _getManufacturers();
// await _getDistributors();
// } else {
// if (mounted) {
// showNotification(context, 'Error: No Internet Connection', false);
if (cache.isNotEmpty) {
_distributorList = cache;
// WidgetsBinding.instance.addPostFrameCallback((_) {
// if (mounted) {
// context.pop();
// }
// });
// }
// }
// } else {
// setState(() {});
// }
if (await InternetConnectionChecker.instance.hasConnection) {
await _getGenerics();
await _getTypes();
await _getManufacturers();
await _getDistributors();
await _getSuppliers();
return true;
} else {
if (mounted) {
showNotification(context, 'Error: No Internet Connection', false);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
context.pop();
}
});
}
return false;
}
}
Future<bool> _getSuppliersCache() async {
final cache = await cacheGetSupplierList(context);
if (cache.isNotEmpty) {
_supplierList = cache;
return true;
} else {
return false;
}
}
void autoRun() async {
final generics = await _getGenericsCache();
final types = await _getTypesCache();
final manufacturers = await _getManufacturersCache();
final distributors = await _getDistributorsCache();
final suppliers = await _getSuppliersCache();
print('generics: $generics');
print('types: $types');
print('manufacturers: $manufacturers');
print('distributors: $distributors');
print('suppliers: $suppliers');
if (!generics || !types || !manufacturers || !distributors || !suppliers) {
if (await InternetConnectionChecker.instance.hasConnection) {
await _getGenerics();
await _getTypes();
await _getManufacturers();
await _getDistributors();
await _getSuppliers();
} else {
if (mounted) {
showNotification(context, 'Error: No Internet Connection', false);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
context.pop();
}
});
}
}
} else {
setState(() {});
}
// if (await InternetConnectionChecker.instance.hasConnection) {
// await _getGenerics();
// await _getTypes();
// await _getManufacturers();
// await _getDistributors();
// await _getSuppliers();
// } else {
// if (mounted) {
// showNotification(context, 'Error: No Internet Connection', false);
// WidgetsBinding.instance.addPostFrameCallback((_) {
// if (mounted) {
// context.pop();
// }
// });
// }
// }
}
void _updateGeneric(dynamic generic) async {
_selectedGeneric = generic;
final catuuid = await _refGenericNames.getCategoryUUID(_selectedGeneric);