added cache for types
This commit is contained in:
parent
bcf9823ffb
commit
5c4c8ceca9
8 changed files with 109 additions and 9 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/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();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import 'package:pharmacy_mobile/blocs/caches/categorylist/functions/cache_setcat
|
|||
import 'package:pharmacy_mobile/blocs/caches/genericlist/functions/cache_setgenericlist.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_generic_names.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';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
|
|
@ -26,6 +27,7 @@ class _MainPageState extends State<MainPage> {
|
|||
final _authService = AuthService();
|
||||
final _refCategories = RefCategories();
|
||||
final _refGenericNames = RefGenericNames();
|
||||
final _refTypes = RefTypes();
|
||||
|
||||
late bool _isLoading = false;
|
||||
|
||||
|
|
@ -95,9 +97,23 @@ class _MainPageState extends State<MainPage> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _getTypeListCache() async {
|
||||
final typeList = await _refTypes.getList();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
await _getCategoryListCache();
|
||||
await _getGenericListCache();
|
||||
await _getTypeListCache();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue