fix caching on add medicines

This commit is contained in:
Patrick Alvin Alcala 2025-03-21 10:20:28 +08:00
parent 5c4c8ceca9
commit 518415aa4e
8 changed files with 116 additions and 26 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/manufacturerlist/manufacturerlist_cache_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/manufacturerlist_cache_event.dart';
Future<List> cacheGetManufacturerList(BuildContext context) async {
try {
final manufacturerListCache = context.read<ManufacturerListBloc>();
manufacturerListCache.add(ManufacturerListCacheGet());
return manufacturerListCache.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/manufacturerlist/manufacturerlist_cache_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/manufacturerlist_cache_event.dart';
Future<bool> cacheSetManufacturerList(BuildContext context, List value) async {
try {
final manufacturerListCache = context.read<ManufacturerListBloc>();
manufacturerListCache.add(ManufacturerListCacheSet(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/manufacturerlist/manufacturerlist_cache_event.dart';
import 'package:pharmacy_mobile/blocs/caches/manufacturerlist/manufacturerlist_cache_state.dart';
class ManufacturerListBloc extends Bloc<ManufacturerListCacheEvent, ManufacturerListCacheState> {
ManufacturerListBloc() : super(ManufacturerListCacheState([])) {
on<ManufacturerListCacheSet>((event, emit) {
emit(ManufacturerListCacheState(event.value));
});
on<ManufacturerListCacheGet>((event, emit) {
emit(state);
});
}
}

View file

@ -0,0 +1,8 @@
abstract class ManufacturerListCacheEvent {}
class ManufacturerListCacheSet extends ManufacturerListCacheEvent {
final List value;
ManufacturerListCacheSet(this.value);
}
class ManufacturerListCacheGet extends ManufacturerListCacheEvent {}

View file

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