add cache for stocks
This commit is contained in:
parent
92df0af895
commit
de5a7c66a3
11 changed files with 134 additions and 3 deletions
14
lib/blocs/caches/stocklist/functions/cache_getstocklist.dart
Normal file
14
lib/blocs/caches/stocklist/functions/cache_getstocklist.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/stocklist/stocklist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/stocklist/stocklist_cache_event.dart';
|
||||
|
||||
Future<List> cacheGetStockList(BuildContext context) async {
|
||||
try {
|
||||
final stockListCache = context.read<StockListBloc>();
|
||||
stockListCache.add(StockListCacheGet());
|
||||
return stockListCache.state.value;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
14
lib/blocs/caches/stocklist/functions/cache_setstocklist.dart
Normal file
14
lib/blocs/caches/stocklist/functions/cache_setstocklist.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/stocklist/stocklist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/stocklist/stocklist_cache_event.dart';
|
||||
|
||||
Future<bool> cacheSetStockList(BuildContext context, List value) async {
|
||||
try {
|
||||
final stockListCache = context.read<StockListBloc>();
|
||||
stockListCache.add(StockListCacheSet(value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
14
lib/blocs/caches/stocklist/stocklist_cache_bloc.dart
Normal file
14
lib/blocs/caches/stocklist/stocklist_cache_bloc.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/stocklist/stocklist_cache_event.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/stocklist/stocklist_cache_state.dart';
|
||||
|
||||
class StockListBloc extends Bloc<StockListCacheEvent, StockListCacheState> {
|
||||
StockListBloc() : super(StockListCacheState([])) {
|
||||
on<StockListCacheSet>((event, emit) {
|
||||
emit(StockListCacheState(event.value));
|
||||
});
|
||||
on<StockListCacheGet>((event, emit) {
|
||||
emit(state);
|
||||
});
|
||||
}
|
||||
}
|
||||
8
lib/blocs/caches/stocklist/stocklist_cache_event.dart
Normal file
8
lib/blocs/caches/stocklist/stocklist_cache_event.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
abstract class StockListCacheEvent {}
|
||||
|
||||
class StockListCacheSet extends StockListCacheEvent {
|
||||
final List value;
|
||||
StockListCacheSet(this.value);
|
||||
}
|
||||
|
||||
class StockListCacheGet extends StockListCacheEvent {}
|
||||
5
lib/blocs/caches/stocklist/stocklist_cache_state.dart
Normal file
5
lib/blocs/caches/stocklist/stocklist_cache_state.dart
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class StockListCacheState {
|
||||
final List value;
|
||||
|
||||
StockListCacheState(this.value);
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ Future<List> cacheGetTypeList(BuildContext context) async {
|
|||
typeListCache.add(TypeListCacheGet());
|
||||
return typeListCache.state.value;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue