added cache for types

This commit is contained in:
Patrick Alvin Alcala 2025-03-20 15:05:21 +08:00
parent bcf9823ffb
commit 5c4c8ceca9
8 changed files with 109 additions and 9 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/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 [];
}
}

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

View file

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

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

View file

@ -0,0 +1,8 @@
abstract class TypeListCacheEvent {}
class TypeListCacheSet extends TypeListCacheEvent {
final List value;
TypeListCacheSet(this.value);
}
class TypeListCacheGet extends TypeListCacheEvent {}

View file

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