added cache for generics
This commit is contained in:
parent
1aa7410e2e
commit
bcf9823ffb
13 changed files with 108 additions and 9 deletions
|
|
@ -10,8 +10,5 @@ class CategoryListBloc extends Bloc<CategoryListCacheEvent, CategoryListCacheSta
|
||||||
on<CategoryListCacheGet>((event, emit) {
|
on<CategoryListCacheGet>((event, emit) {
|
||||||
emit(state);
|
emit(state);
|
||||||
});
|
});
|
||||||
on<CategoryListCacheCheck>((event, emit) {
|
|
||||||
emit(state);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,3 @@ class CategoryListCacheSet extends CategoryListCacheEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
class CategoryListCacheGet extends CategoryListCacheEvent {}
|
class CategoryListCacheGet extends CategoryListCacheEvent {}
|
||||||
|
|
||||||
class CategoryListCacheCheck extends CategoryListCacheEvent {}
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_bloc.dart';
|
||||||
|
|
||||||
|
void cacheCategoryListDispose(BuildContext context) async {
|
||||||
|
final cache = context.read<CategoryListBloc>();
|
||||||
|
cache.close();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_bloc.dart';
|
||||||
|
|
||||||
|
void cacheGenericListDispose(BuildContext context) async {
|
||||||
|
final cache = context.read<GenericListBloc>();
|
||||||
|
cache.close();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_event.dart';
|
||||||
|
|
||||||
|
Future<List> cacheGetGenericList(BuildContext context) async {
|
||||||
|
try {
|
||||||
|
final genericListCache = context.read<GenericListBloc>();
|
||||||
|
genericListCache.add(GenericListCacheGet());
|
||||||
|
return genericListCache.state.value;
|
||||||
|
} catch (e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_event.dart';
|
||||||
|
|
||||||
|
Future<bool> cacheSetGenericList(BuildContext context, List value) async {
|
||||||
|
try {
|
||||||
|
final genericListCache = context.read<GenericListBloc>();
|
||||||
|
genericListCache.add(GenericListCacheSet(value));
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
lib/blocs/caches/genericlist/genericlist_cache_bloc.dart
Normal file
14
lib/blocs/caches/genericlist/genericlist_cache_bloc.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_event.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_state.dart';
|
||||||
|
|
||||||
|
class GenericListBloc extends Bloc<GenericListCacheEvent, GenericListCacheState> {
|
||||||
|
GenericListBloc() : super(GenericListCacheState([])) {
|
||||||
|
on<GenericListCacheSet>((event, emit) {
|
||||||
|
emit(GenericListCacheState(event.value));
|
||||||
|
});
|
||||||
|
on<GenericListCacheGet>((event, emit) {
|
||||||
|
emit(state);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
abstract class GenericListCacheEvent {}
|
||||||
|
|
||||||
|
class GenericListCacheSet extends GenericListCacheEvent {
|
||||||
|
final List value;
|
||||||
|
GenericListCacheSet(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class GenericListCacheGet extends GenericListCacheEvent {}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class GenericListCacheState {
|
||||||
|
final List value;
|
||||||
|
|
||||||
|
GenericListCacheState(this.value);
|
||||||
|
}
|
||||||
8
lib/blocs/guest/functions/bloc_guest_dispose.dart
Normal file
8
lib/blocs/guest/functions/bloc_guest_dispose.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/guest/guest_bloc.dart';
|
||||||
|
|
||||||
|
void blocGuestDispose(BuildContext context) async {
|
||||||
|
final guestBloc = context.read<GuestBloc>();
|
||||||
|
guestBloc.close();
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ 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/genericlist/genericlist_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/user/user_bloc.dart';
|
import 'package:pharmacy_mobile/blocs/user/user_bloc.dart';
|
||||||
import 'package:pharmacy_mobile/pages/add_category_page.dart';
|
import 'package:pharmacy_mobile/pages/add_category_page.dart';
|
||||||
|
|
@ -128,6 +129,9 @@ class MyApp extends StatelessWidget {
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => CategoryListBloc(),
|
create: (context) => CategoryListBloc(),
|
||||||
),
|
),
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => GenericListBloc(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: MaterialApp.router(
|
child: MaterialApp.router(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ 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/genericlist/functions/cache_getgenericlist.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';
|
||||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||||
|
|
@ -58,7 +59,14 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
late String imageUrl = '';
|
late String imageUrl = '';
|
||||||
|
|
||||||
Future<void> _getGenerics() async {
|
Future<void> _getGenerics() async {
|
||||||
|
final cache = await cacheGetGenericList(context);
|
||||||
|
|
||||||
|
if (cache.isNotEmpty) {
|
||||||
|
_genericNameList = cache;
|
||||||
|
} else {
|
||||||
_genericNameList = await _refGenericNames.getList();
|
_genericNameList = await _refGenericNames.getList();
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
checkResult(context, _genericNameList, 'Generics');
|
checkResult(context, _genericNameList, 'Generics');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:gap/gap.dart';
|
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_getcategorylist.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/genericlist/functions/cache_setgenericlist.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||||
|
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/menu_widget.dart';
|
import 'package:pharmacy_mobile/widgets/menu_widget.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||||
|
|
@ -24,6 +25,7 @@ class MainPage extends StatefulWidget {
|
||||||
class _MainPageState extends State<MainPage> {
|
class _MainPageState extends State<MainPage> {
|
||||||
final _authService = AuthService();
|
final _authService = AuthService();
|
||||||
final _refCategories = RefCategories();
|
final _refCategories = RefCategories();
|
||||||
|
final _refGenericNames = RefGenericNames();
|
||||||
|
|
||||||
late bool _isLoading = false;
|
late bool _isLoading = false;
|
||||||
|
|
||||||
|
|
@ -76,15 +78,26 @@ class _MainPageState extends State<MainPage> {
|
||||||
if (!setCache) {
|
if (!setCache) {
|
||||||
// ignore: use_build_context_synchronously
|
// ignore: use_build_context_synchronously
|
||||||
showNotification(context, 'Caching failed', false);
|
showNotification(context, 'Caching failed', false);
|
||||||
} else {
|
}
|
||||||
print('Caching Success');
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _getGenericListCache() async {
|
||||||
|
final genericNameList = await _refGenericNames.getList();
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoRun() async {
|
void autoRun() async {
|
||||||
await _getCategoryListCache();
|
await _getCategoryListCache();
|
||||||
|
await _getGenericListCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue