fix cache error
This commit is contained in:
parent
6bdc9a7c6c
commit
0561d9a9b4
3 changed files with 112 additions and 41 deletions
|
|
@ -2,10 +2,12 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:pharmacy_mobile/auth/auth_gate.dart';
|
import 'package:pharmacy_mobile/auth/auth_gate.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/distributorlist/distributorlist_cache_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/manufacturerlist_cache_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/manufacturerlist_cache_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/medicinelist/medicinelist_cache_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/caches/medicinelist/medicinelist_cache_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/stocklist/stocklist_cache_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/caches/stocklist/stocklist_cache_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/supplierlist/supplierlist_cache_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/guest/guest_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/guest/guest_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/language/language_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/language/language_bloc.dart';
|
||||||
|
|
@ -287,6 +289,12 @@ class MyApp extends StatelessWidget {
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => LanguageBloc(),
|
create: (context) => LanguageBloc(),
|
||||||
),
|
),
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => DistributorListBloc(),
|
||||||
|
),
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => SupplierListBloc(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:internet_connection_checker/internet_connection_checker.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/genericlist/functions/cache_getgenericlist.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/functions/cache_getmanufacturerlist.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/blocs/caches/typelist/functions/cache_gettypelist.dart';
|
||||||
import 'package:pharmacy_mobile/functions/barcode_scan_function.dart';
|
import 'package:pharmacy_mobile/functions/barcode_scan_function.dart';
|
||||||
import 'package:pharmacy_mobile/functions/checkresult_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);
|
final cache = await cacheGetManufacturerList(context);
|
||||||
|
|
||||||
if (cache.isNotEmpty) {
|
if (cache.isNotEmpty) {
|
||||||
|
|
@ -141,32 +143,44 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> _getDistributorsCache() async {
|
||||||
|
final cache = await cacheGetDistributorList(context);
|
||||||
|
|
||||||
|
if (cache.isNotEmpty) {
|
||||||
|
_distributorList = cache;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> _getSuppliersCache() async {
|
||||||
|
final cache = await cacheGetSupplierList(context);
|
||||||
|
|
||||||
|
if (cache.isNotEmpty) {
|
||||||
|
_supplierList = cache;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void autoRun() async {
|
void autoRun() async {
|
||||||
// final generics = await _getGenericsCache();
|
final generics = await _getGenericsCache();
|
||||||
// final types = await _getTypesCache();
|
final types = await _getTypesCache();
|
||||||
// final manufacturers = await _getManufacturerCache();
|
final manufacturers = await _getManufacturersCache();
|
||||||
|
final distributors = await _getDistributorsCache();
|
||||||
|
final suppliers = await _getSuppliersCache();
|
||||||
|
|
||||||
// if (!generics || !types || !manufacturers) {
|
print('generics: $generics');
|
||||||
// if (await InternetConnectionChecker.instance.hasConnection) {
|
print('types: $types');
|
||||||
// await _getGenerics();
|
print('manufacturers: $manufacturers');
|
||||||
// await _getTypes();
|
print('distributors: $distributors');
|
||||||
// await _getManufacturers();
|
print('suppliers: $suppliers');
|
||||||
// await _getDistributors();
|
|
||||||
// } else {
|
|
||||||
// if (mounted) {
|
|
||||||
// showNotification(context, 'Error: No Internet Connection', false);
|
|
||||||
|
|
||||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
// if (mounted) {
|
|
||||||
// context.pop();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// setState(() {});
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
if (!generics || !types || !manufacturers || !distributors || !suppliers) {
|
||||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||||
await _getGenerics();
|
await _getGenerics();
|
||||||
await _getTypes();
|
await _getTypes();
|
||||||
|
|
@ -184,6 +198,27 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} 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 {
|
void _updateGeneric(dynamic generic) async {
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,19 @@ import 'package:gap/gap.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:pharmacy_mobile/auth/auth_service.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/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/genericlist/functions/cache_setgenericlist.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/functions/cache_setmanufacturerlist.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/medicinelist/functions/cache_setmedicinelist.dart';
|
||||||
import 'package:pharmacy_mobile/blocs/caches/stocklist/functions/cache_setstocklist.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/blocs/caches/typelist/functions/cache_settypelist.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_categories.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_generic_names.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_manufacturers.dart';
|
import 'package:pharmacy_mobile/tables/ref_manufacturers.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_medicines.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/ref_types.dart';
|
||||||
import 'package:pharmacy_mobile/tables/stocks.dart';
|
import 'package:pharmacy_mobile/tables/stocks.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||||
|
|
@ -38,6 +42,8 @@ class _MainPageState extends State<MainPage> {
|
||||||
final _refManufacturers = RefManufacturers();
|
final _refManufacturers = RefManufacturers();
|
||||||
final _refMedicines = RefMedicines();
|
final _refMedicines = RefMedicines();
|
||||||
final _stocks = Stocks();
|
final _stocks = Stocks();
|
||||||
|
final _refDistributors = RefDistributors();
|
||||||
|
final _refSuppliers = RefSuppliers();
|
||||||
|
|
||||||
late bool _isLoading = false;
|
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 {
|
void autoRun() async {
|
||||||
await _getCategoryListCache();
|
await _getCategoryListCache();
|
||||||
await _getGenericListCache();
|
await _getGenericListCache();
|
||||||
|
|
@ -130,6 +156,8 @@ class _MainPageState extends State<MainPage> {
|
||||||
await _getManufacturerListCache();
|
await _getManufacturerListCache();
|
||||||
await _getMedicineListCache();
|
await _getMedicineListCache();
|
||||||
await _getStockListCache();
|
await _getStockListCache();
|
||||||
|
await _getDistributorListCache();
|
||||||
|
await _getSupplierListCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue