added cache for suppliers
This commit is contained in:
parent
f2fdfc644a
commit
6bdc9a7c6c
5 changed files with 55 additions and 0 deletions
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/supplierlist/supplierlist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/supplierlist/supplierlist_cache_event.dart';
|
||||
|
||||
Future<List> cacheGetSupplierList(BuildContext context) async {
|
||||
try {
|
||||
final supplierListCache = context.read<SupplierListBloc>();
|
||||
supplierListCache.add(SupplierListCacheGet());
|
||||
return supplierListCache.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/supplierlist/supplierlist_cache_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/supplierlist/supplierlist_cache_event.dart';
|
||||
|
||||
Future<bool> cacheSetSupplierList(BuildContext context, List value) async {
|
||||
try {
|
||||
final supplierListCache = context.read<SupplierListBloc>();
|
||||
supplierListCache.add(SupplierListCacheSet(value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
14
lib/blocs/caches/supplierlist/supplierlist_cache_bloc.dart
Normal file
14
lib/blocs/caches/supplierlist/supplierlist_cache_bloc.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/supplierlist/supplierlist_cache_event.dart';
|
||||
import 'package:pharmacy_mobile/blocs/caches/supplierlist/supplierlist_cache_state.dart';
|
||||
|
||||
class SupplierListBloc extends Bloc<SupplierListCacheEvent, SupplierListCacheState> {
|
||||
SupplierListBloc() : super(SupplierListCacheState([])) {
|
||||
on<SupplierListCacheSet>((event, emit) {
|
||||
emit(SupplierListCacheState(event.value));
|
||||
});
|
||||
on<SupplierListCacheGet>((event, emit) {
|
||||
emit(state);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
abstract class SupplierListCacheEvent {}
|
||||
|
||||
class SupplierListCacheSet extends SupplierListCacheEvent {
|
||||
final List value;
|
||||
SupplierListCacheSet(this.value);
|
||||
}
|
||||
|
||||
class SupplierListCacheGet extends SupplierListCacheEvent {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class SupplierListCacheState {
|
||||
final List value;
|
||||
|
||||
SupplierListCacheState(this.value);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue