added cache for categories
This commit is contained in:
parent
753c730588
commit
1aa7410e2e
14 changed files with 195 additions and 63 deletions
|
|
@ -3,6 +3,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|||
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_getcategorylist.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/categorylist/functions/cache_setcategorylist.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_categories.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';
|
||||
|
|
@ -20,6 +23,7 @@ class MainPage extends StatefulWidget {
|
|||
|
||||
class _MainPageState extends State<MainPage> {
|
||||
final _authService = AuthService();
|
||||
final _refCategories = RefCategories();
|
||||
|
||||
late bool _isLoading = false;
|
||||
|
||||
|
|
@ -45,6 +49,50 @@ class _MainPageState extends State<MainPage> {
|
|||
}
|
||||
}
|
||||
|
||||
// void _getList() async {
|
||||
// _categoryList = await _refCategories.getList();
|
||||
|
||||
// if (_categoryList.isEmpty) {
|
||||
// if (mounted) {
|
||||
// showNotification(context, 'Error: No Categories Found', false);
|
||||
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// if (mounted) {
|
||||
// context.push('/main');
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// setState(() => {});
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> _getCategoryListCache() async {
|
||||
final categoryList = await _refCategories.getList();
|
||||
|
||||
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);
|
||||
} else {
|
||||
print('Caching Success');
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
await _getCategoryListCache();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
autoRun();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue