mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00

* Refactor import function & Allow import local comics without copying them to local path. * android: use file_picker instead, support directory access for android 10 * Improve import logic * Fix sql query. * Add ability to remove invalid favorite items. * Perform sort before choosing cover * Revert changes of "use file_picker instead". * Try catch on "check update" * Added module 'flutter_saf' * gitignore * remove unsupported arch in build.gradle * Use flutter_saf to handle android's directory and files, improve import logic. * revert changes of 'requestLegacyExternalStorage' * fix cbz import * openDirectoryPlatform * Remove double check on source folder * use openFilePlatform * remove unused import * improve local comic's path handling * bump version * fix pubspec format * return null when comic folder is empty
51 lines
1.5 KiB
Dart
51 lines
1.5 KiB
Dart
import 'dart:async' show Future, StreamController;
|
|
import 'dart:io';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:venera/network/images.dart';
|
|
import 'package:venera/utils/io.dart';
|
|
import 'base_image_provider.dart';
|
|
import 'cached_image.dart' as image_provider;
|
|
|
|
class CachedImageProvider
|
|
extends BaseImageProvider<image_provider.CachedImageProvider> {
|
|
/// Image provider for normal image.
|
|
///
|
|
/// [url] is the url of the image. Local file path is also supported.
|
|
const CachedImageProvider(this.url, {this.headers, this.sourceKey, this.cid});
|
|
|
|
final String url;
|
|
|
|
final Map<String, String>? headers;
|
|
|
|
final String? sourceKey;
|
|
|
|
final String? cid;
|
|
|
|
@override
|
|
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async {
|
|
if(url.startsWith("file://")) {
|
|
var file = openFilePlatform(url.substring(7));
|
|
return file.readAsBytes();
|
|
}
|
|
await for (var progress in ImageDownloader.loadThumbnail(url, sourceKey, cid)) {
|
|
chunkEvents.add(ImageChunkEvent(
|
|
cumulativeBytesLoaded: progress.currentBytes,
|
|
expectedTotalBytes: progress.totalBytes,
|
|
));
|
|
if(progress.imageBytes != null) {
|
|
return progress.imageBytes!;
|
|
}
|
|
}
|
|
throw "Error: Empty response body.";
|
|
}
|
|
|
|
@override
|
|
Future<CachedImageProvider> obtainKey(ImageConfiguration configuration) {
|
|
return SynchronousFuture(this);
|
|
}
|
|
|
|
@override
|
|
String get key => url + (sourceKey ?? "") + (cid ?? "");
|
|
}
|