added cache for suppliers

This commit is contained in:
Patrick Alvin Alcala 2025-04-22 11:38:53 +08:00
parent f2fdfc644a
commit 6bdc9a7c6c
5 changed files with 55 additions and 0 deletions

View file

@ -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 [];
}
}

View file

@ -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;
}
}

View 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);
});
}
}

View file

@ -0,0 +1,8 @@
abstract class SupplierListCacheEvent {}
class SupplierListCacheSet extends SupplierListCacheEvent {
final List value;
SupplierListCacheSet(this.value);
}
class SupplierListCacheGet extends SupplierListCacheEvent {}

View file

@ -0,0 +1,5 @@
class SupplierListCacheState {
final List value;
SupplierListCacheState(this.value);
}