|
|
@@ -1,8 +1,10 @@
|
|
|
+import 'dart:io';
|
|
|
+
|
|
|
import 'package:bloc/bloc.dart';
|
|
|
+import 'package:default_saver/default_saver.dart';
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
-import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
|
|
import 'package:network_image_cached/src/http_request.dart';
|
|
|
|
|
|
part 'cashed_image_event.dart';
|
|
|
@@ -11,8 +13,6 @@ part 'cashed_image_state.dart';
|
|
|
Map<String, Uint8List> mapcahed = <String, Uint8List>{};
|
|
|
|
|
|
class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
|
- DefaultCacheManager defaultCacheManager = DefaultCacheManager();
|
|
|
-
|
|
|
CashedImageBloc() : super(CashedImageInitial()) {
|
|
|
on<GetStartImageEvent>((event, emit) async {
|
|
|
emit(CashedImageLoadingState());
|
|
|
@@ -22,7 +22,8 @@ class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
|
httpHeaders: event.httpHeaders,
|
|
|
);
|
|
|
if (event.cached) {
|
|
|
- FileInfo? fileInfo;
|
|
|
+ DefaulFileManager defaulFileManager = await DefaulFileManager.init();
|
|
|
+
|
|
|
Uint8List? bytes;
|
|
|
|
|
|
final String ckey;
|
|
|
@@ -46,9 +47,9 @@ class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
|
mapcahed.clear();
|
|
|
}
|
|
|
if (mapcahed[ckey] == null) {
|
|
|
- fileInfo = await defaultCacheManager.getFileFromCache(ckey);
|
|
|
+ File? fileInfo = await defaulFileManager.getFile(ckey);
|
|
|
if (fileInfo != null) {
|
|
|
- mapcahed[ckey] = await fileInfo.file.readAsBytes();
|
|
|
+ mapcahed[ckey] = await fileInfo.readAsBytes();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -63,11 +64,12 @@ class CashedImageBloc extends Bloc<CashedImageEvent, CashedImageState> {
|
|
|
try {
|
|
|
Uint8List uint8list = await httpGetImage.getDataObjectIsolate();
|
|
|
if (event.cached) {
|
|
|
+ DefaulFileManager defaulFileManager = await DefaulFileManager.init();
|
|
|
if (event.cachkey != null) {
|
|
|
- defaultCacheManager.putFile(event.cachkey!, uint8list);
|
|
|
+ defaulFileManager.saveFile(key: event.cachkey!, bytes: uint8list);
|
|
|
mapcahed[event.cachkey!] = uint8list;
|
|
|
} else {
|
|
|
- defaultCacheManager.putFile(event.url, uint8list);
|
|
|
+ defaulFileManager.saveFile(key: event.url, bytes: uint8list);
|
|
|
mapcahed[event.url] = uint8list;
|
|
|
}
|
|
|
}
|