|
@@ -10,6 +10,8 @@ part 'cashed_image_state.dart';
|
|
|
|
|
|
|
|
class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
|
DefaultCacheManager defaultCacheManager = DefaultCacheManager();
|
|
DefaultCacheManager defaultCacheManager = DefaultCacheManager();
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Uint8List> mapcahed = <String, Uint8List>{};
|
|
|
CashedImageBloc() : super(CashedImageInitial()) {
|
|
CashedImageBloc() : super(CashedImageInitial()) {
|
|
|
on<GetStartImageEvent>((event, emit) async {
|
|
on<GetStartImageEvent>((event, emit) async {
|
|
|
emit(CashedImageLoadingState());
|
|
emit(CashedImageLoadingState());
|
|
@@ -20,14 +22,29 @@ class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
|
);
|
|
);
|
|
|
if (event.cached) {
|
|
if (event.cached) {
|
|
|
FileInfo? fileInfo;
|
|
FileInfo? fileInfo;
|
|
|
|
|
+ Uint8List? bytes;
|
|
|
if (event.cachkey != null) {
|
|
if (event.cachkey != null) {
|
|
|
- fileInfo = await defaultCacheManager.getFileFromCache(event.cachkey!);
|
|
|
|
|
|
|
+ if (mapcahed[event.cachkey!] == null) {
|
|
|
|
|
+ fileInfo = await defaultCacheManager.getFileFromCache(
|
|
|
|
|
+ event.cachkey!,
|
|
|
|
|
+ );
|
|
|
|
|
+ if (fileInfo != null) {
|
|
|
|
|
+ mapcahed[event.cachkey!] = await fileInfo.file.readAsBytes();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ bytes = mapcahed[event.cachkey!];
|
|
|
} else {
|
|
} else {
|
|
|
- fileInfo = await defaultCacheManager.getFileFromCache(event.url);
|
|
|
|
|
|
|
+ if (mapcahed[event.url] == null) {
|
|
|
|
|
+ fileInfo = await defaultCacheManager.getFileFromCache(event.url);
|
|
|
|
|
+ if (fileInfo != null) {
|
|
|
|
|
+ mapcahed[event.url] = await fileInfo.file.readAsBytes();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ bytes = mapcahed[event.url];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (fileInfo != null) {
|
|
|
|
|
- emit(CashedImageGetState(bytes: await fileInfo.file.readAsBytes()));
|
|
|
|
|
|
|
+ if (bytes != null) {
|
|
|
|
|
+ emit(CashedImageGetState(bytes: bytes));
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -37,8 +54,10 @@ class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
|
if (event.cached) {
|
|
if (event.cached) {
|
|
|
if (event.cachkey != null) {
|
|
if (event.cachkey != null) {
|
|
|
defaultCacheManager.putFile(event.cachkey!, uint8list);
|
|
defaultCacheManager.putFile(event.cachkey!, uint8list);
|
|
|
|
|
+ mapcahed[event.cachkey!] = uint8list;
|
|
|
} else {
|
|
} else {
|
|
|
defaultCacheManager.putFile(event.url, uint8list);
|
|
defaultCacheManager.putFile(event.url, uint8list);
|
|
|
|
|
+ mapcahed[event.url] = uint8list;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|