added cache for categories
This commit is contained in:
parent
753c730588
commit
1aa7410e2e
14 changed files with 195 additions and 63 deletions
17
lib/blocs/caches/categorylist/categorylist_cache_bloc.dart
Normal file
17
lib/blocs/caches/categorylist/categorylist_cache_bloc.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_event.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_state.dart';
|
||||
|
||||
class CategoryListBloc extends Bloc<CategoryListCacheEvent, CategoryListCacheState> {
|
||||
CategoryListBloc() : super(CategoryListCacheState([])) {
|
||||
on<CategoryListCacheSet>((event, emit) {
|
||||
emit(CategoryListCacheState(event.value));
|
||||
});
|
||||
on<CategoryListCacheGet>((event, emit) {
|
||||
emit(state);
|
||||
});
|
||||
on<CategoryListCacheCheck>((event, emit) {
|
||||
emit(state);
|
||||
});
|
||||
}
|
||||
}
|
||||
10
lib/blocs/caches/categorylist/categorylist_cache_event.dart
Normal file
10
lib/blocs/caches/categorylist/categorylist_cache_event.dart
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
abstract class CategoryListCacheEvent {}
|
||||
|
||||
class CategoryListCacheSet extends CategoryListCacheEvent {
|
||||
final List value;
|
||||
CategoryListCacheSet(this.value);
|
||||
}
|
||||
|
||||
class CategoryListCacheGet extends CategoryListCacheEvent {}
|
||||
|
||||
class CategoryListCacheCheck extends CategoryListCacheEvent {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class CategoryListCacheState {
|
||||
final List value;
|
||||
|
||||
CategoryListCacheState(this.value);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_event.dart';
|
||||
|
||||
Future<List> cacheGetCategoryList(BuildContext context) async {
|
||||
try {
|
||||
final categoryListCache = context.read<CategoryListBloc>();
|
||||
categoryListCache.add(CategoryListCacheGet());
|
||||
return categoryListCache.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/categorylist/categorylist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_event.dart';
|
||||
|
||||
Future<bool> cacheSetCategoryList(BuildContext context, List value) async {
|
||||
try {
|
||||
final categoryListCache = context.read<CategoryListBloc>();
|
||||
categoryListCache.add(CategoryListCacheSet(value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue