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

@ -4,15 +4,19 @@ import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:pharmacy_mobile/auth/auth_service.dart';
import 'package:pharmacy_mobile/blocs/caches/categorylist/functions/cache_setcategorylist.dart';
import 'package:pharmacy_mobile/blocs/caches/distributorlist/functions/cache_setdistributorlist.dart';
import 'package:pharmacy_mobile/blocs/caches/genericlist/functions/cache_setgenericlist.dart';
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/functions/cache_setmanufacturerlist.dart';
import 'package:pharmacy_mobile/blocs/caches/medicinelist/functions/cache_setmedicinelist.dart';
import 'package:pharmacy_mobile/blocs/caches/stocklist/functions/cache_setstocklist.dart';
import 'package:pharmacy_mobile/blocs/caches/supplierlist/functions/cache_setsupplierlist.dart';
import 'package:pharmacy_mobile/blocs/caches/typelist/functions/cache_settypelist.dart';
import 'package:pharmacy_mobile/tables/ref_categories.dart';
import 'package:pharmacy_mobile/tables/ref_distributors.dart';
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
import 'package:pharmacy_mobile/tables/ref_manufacturers.dart';
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
import 'package:pharmacy_mobile/tables/ref_suppliers.dart';
import 'package:pharmacy_mobile/tables/ref_types.dart';
import 'package:pharmacy_mobile/tables/stocks.dart';
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
@ -38,6 +42,8 @@ class _MainPageState extends State<MainPage> {
final _refManufacturers = RefManufacturers();
final _refMedicines = RefMedicines();
final _stocks = Stocks();
final _refDistributors = RefDistributors();
final _refSuppliers = RefSuppliers();
late bool _isLoading = false;
@ -123,6 +129,26 @@ class _MainPageState extends State<MainPage> {
}
}
Future<void> _getDistributorListCache() async {
final distributorList = await _refDistributors.getList();
if (distributorList.isNotEmpty) {
// ignore: use_build_context_synchronously
final setCache = await cacheSetDistributorList(context, distributorList);
if (!setCache) {}
}
}
Future<void> _getSupplierListCache() async {
final supplierList = await _refSuppliers.getList();
if (supplierList.isNotEmpty) {
// ignore: use_build_context_synchronously
final setCache = await cacheSetSupplierList(context, supplierList);
if (!setCache) {}
}
}
void autoRun() async {
await _getCategoryListCache();
await _getGenericListCache();
@ -130,6 +156,8 @@ class _MainPageState extends State<MainPage> {
await _getManufacturerListCache();
await _getMedicineListCache();
await _getStockListCache();
await _getDistributorListCache();
await _getSupplierListCache();
}
@override