added cache for types
This commit is contained in:
parent
bcf9823ffb
commit
5c4c8ceca9
8 changed files with 109 additions and 9 deletions
14
lib/blocs/caches/typelist/functions/cache_gettypelist.dart
Normal file
14
lib/blocs/caches/typelist/functions/cache_gettypelist.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_event.dart';
|
||||
|
||||
Future<List> cacheGetTypeList(BuildContext context) async {
|
||||
try {
|
||||
final typeListCache = context.read<TypeListBloc>();
|
||||
typeListCache.add(TypeListCacheGet());
|
||||
return typeListCache.state.value;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
14
lib/blocs/caches/typelist/functions/cache_settypelist.dart
Normal file
14
lib/blocs/caches/typelist/functions/cache_settypelist.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_event.dart';
|
||||
|
||||
Future<bool> cacheSetTypeList(BuildContext context, List value) async {
|
||||
try {
|
||||
final typeListCache = context.read<TypeListBloc>();
|
||||
typeListCache.add(TypeListCacheSet(value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_bloc.dart';
|
||||
|
||||
void cacheTypeListDispose(BuildContext context) async {
|
||||
final cache = context.read<TypeListBloc>();
|
||||
cache.close();
|
||||
}
|
||||
14
lib/blocs/caches/typelist/typelist_cache_bloc.dart
Normal file
14
lib/blocs/caches/typelist/typelist_cache_bloc.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_event.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/typelist/typelist_cache_state.dart';
|
||||
|
||||
class TypeListBloc extends Bloc<TypeListCacheEvent, TypeListCacheState> {
|
||||
TypeListBloc() : super(TypeListCacheState([])) {
|
||||
on<TypeListCacheSet>((event, emit) {
|
||||
emit(TypeListCacheState(event.value));
|
||||
});
|
||||
on<TypeListCacheGet>((event, emit) {
|
||||
emit(state);
|
||||
});
|
||||
}
|
||||
}
|
||||
8
lib/blocs/caches/typelist/typelist_cache_event.dart
Normal file
8
lib/blocs/caches/typelist/typelist_cache_event.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
abstract class TypeListCacheEvent {}
|
||||
|
||||
class TypeListCacheSet extends TypeListCacheEvent {
|
||||
final List value;
|
||||
TypeListCacheSet(this.value);
|
||||
}
|
||||
|
||||
class TypeListCacheGet extends TypeListCacheEvent {}
|
||||
5
lib/blocs/caches/typelist/typelist_cache_state.dart
Normal file
5
lib/blocs/caches/typelist/typelist_cache_state.dart
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class TypeListCacheState {
|
||||
final List value;
|
||||
|
||||
TypeListCacheState(this.value);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue