added cache for generics

This commit is contained in:
Patrick Alvin Alcala 2025-03-20 14:17:01 +08:00
parent 1aa7410e2e
commit bcf9823ffb
13 changed files with 108 additions and 9 deletions

View file

@ -10,8 +10,5 @@ class CategoryListBloc extends Bloc<CategoryListCacheEvent, CategoryListCacheSta
on<CategoryListCacheGet>((event, emit) {
emit(state);
});
on<CategoryListCacheCheck>((event, emit) {
emit(state);
});
}
}

View file

@ -6,5 +6,3 @@ class CategoryListCacheSet extends CategoryListCacheEvent {
}
class CategoryListCacheGet extends CategoryListCacheEvent {}
class CategoryListCacheCheck extends CategoryListCacheEvent {}

View file

@ -0,0 +1,8 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/categorylist/categorylist_cache_bloc.dart';
void cacheCategoryListDispose(BuildContext context) async {
final cache = context.read<CategoryListBloc>();
cache.close();
}

View file

@ -0,0 +1,8 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_bloc.dart';
void cacheGenericListDispose(BuildContext context) async {
final cache = context.read<GenericListBloc>();
cache.close();
}

View file

@ -0,0 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_event.dart';
Future<List> cacheGetGenericList(BuildContext context) async {
try {
final genericListCache = context.read<GenericListBloc>();
genericListCache.add(GenericListCacheGet());
return genericListCache.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/genericlist/genericlist_cache_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_event.dart';
Future<bool> cacheSetGenericList(BuildContext context, List value) async {
try {
final genericListCache = context.read<GenericListBloc>();
genericListCache.add(GenericListCacheSet(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/genericlist/genericlist_cache_event.dart';
import 'package:pharmacy_mobile/blocs/caches/genericlist/genericlist_cache_state.dart';
class GenericListBloc extends Bloc<GenericListCacheEvent, GenericListCacheState> {
GenericListBloc() : super(GenericListCacheState([])) {
on<GenericListCacheSet>((event, emit) {
emit(GenericListCacheState(event.value));
});
on<GenericListCacheGet>((event, emit) {
emit(state);
});
}
}

View file

@ -0,0 +1,8 @@
abstract class GenericListCacheEvent {}
class GenericListCacheSet extends GenericListCacheEvent {
final List value;
GenericListCacheSet(this.value);
}
class GenericListCacheGet extends GenericListCacheEvent {}

View file

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

View file

@ -0,0 +1,8 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pharmacy_mobile/blocs/guest/guest_bloc.dart';
void blocGuestDispose(BuildContext context) async {
final guestBloc = context.read<GuestBloc>();
guestBloc.close();
}