fix caching on add medicines

This commit is contained in:
Patrick Alvin Alcala 2025-03-21 10:20:28 +08:00
parent 5c4c8ceca9
commit 518415aa4e
8 changed files with 116 additions and 26 deletions

View file

@ -5,8 +5,11 @@ 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/genericlist/functions/cache_setgenericlist.dart';
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/functions/cache_setmanufacturerlist.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_generic_names.dart';
import 'package:pharmacy_mobile/tables/ref_manufacturers.dart';
import 'package:pharmacy_mobile/tables/ref_types.dart';
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
import 'package:pharmacy_mobile/widgets/menu_widget.dart';
@ -28,6 +31,7 @@ class _MainPageState extends State<MainPage> {
final _refCategories = RefCategories();
final _refGenericNames = RefGenericNames();
final _refTypes = RefTypes();
final _refManufacturers = RefManufacturers();
late bool _isLoading = false;
@ -77,10 +81,7 @@ class _MainPageState extends State<MainPage> {
if (categoryList.isNotEmpty) {
// ignore: use_build_context_synchronously
final setCache = await cacheSetCategoryList(context, categoryList);
if (!setCache) {
// ignore: use_build_context_synchronously
showNotification(context, 'Caching failed', false);
}
if (!setCache) {}
}
}
@ -90,10 +91,7 @@ class _MainPageState extends State<MainPage> {
if (genericNameList.isNotEmpty) {
// ignore: use_build_context_synchronously
final setCache = await cacheSetGenericList(context, genericNameList);
if (!setCache) {
// ignore: use_build_context_synchronously
showNotification(context, 'Caching failed', false);
}
if (!setCache) {}
}
}
@ -102,11 +100,18 @@ class _MainPageState extends State<MainPage> {
if (typeList.isNotEmpty) {
// ignore: use_build_context_synchronously
final setCache = await cacheSetGenericList(context, typeList);
if (!setCache) {
// ignore: use_build_context_synchronously
showNotification(context, 'Caching failed', false);
}
final setCache = await cacheSetTypeList(context, typeList);
if (!setCache) {}
}
}
Future<void> _getManufacturerListCache() async {
final manufacturerList = await _refManufacturers.getList();
if (manufacturerList.isNotEmpty) {
// ignore: use_build_context_synchronously
final setCache = await cacheSetManufacturerList(context, manufacturerList);
if (!setCache) {}
}
}
@ -114,6 +119,7 @@ class _MainPageState extends State<MainPage> {
await _getCategoryListCache();
await _getGenericListCache();
await _getTypeListCache();
await _getManufacturerListCache();
}
@override