Add support to copy image and url in viewer

This commit is contained in:
2024-10-29 10:01:56 +00:00
committed by GitHub
parent 57f54d319b
commit 6d2c445cd4
5 changed files with 79 additions and 7 deletions

View File

@@ -28,7 +28,8 @@ class DioImage extends ImageProvider<DioImage> {
///
/// The arguments [url] and [scale] must not be null.
/// [dio] will be the default [Dio] if not set.
DioImage.string(String url, {this.scale = 1.0, this.headers, Dio? dio})
DioImage.string(String url,
{this.scale = 1.0, this.headers, this.onData, Dio? dio})
: dio = dio ?? defaultDio,
url = Uri.parse(url);
@@ -36,7 +37,7 @@ class DioImage extends ImageProvider<DioImage> {
///
/// The arguments [url] and [scale] must not be null.
/// [dio] will be the default [Dio] if not set.
DioImage(this.url, {this.scale = 1.0, this.headers, Dio? dio})
DioImage(this.url, {this.scale = 1.0, this.headers, this.onData, Dio? dio})
: dio = dio ?? defaultDio;
/// The URL from which the image will be fetched.
@@ -53,6 +54,8 @@ class DioImage extends ImageProvider<DioImage> {
/// [dio] will be the default [Dio] if not set.
final Dio dio;
final void Function(Uint8List, Headers, String)? onData;
@override
Future<DioImage> obtainKey(ImageConfiguration configuration) {
return SynchronousFuture<DioImage>(this);
@@ -89,6 +92,10 @@ class DioImage extends ImageProvider<DioImage> {
try {
final cache = await imageCaches.getCache(url.toString());
if (cache != null) {
if (onData != null) {
onData!(cache!.$1, Headers.fromMap(cache!.$2),
cache!.$3 ?? url.toString());
}
final buffer = await ui.ImmutableBuffer.fromUint8List(cache!.$1);
return decode(buffer);
}
@@ -124,6 +131,10 @@ class DioImage extends ImageProvider<DioImage> {
);
}
if (onData != null) {
onData!(bytes, response.headers, response.realUri.toString());
}
if (isImageCacheEnabled) {
try {
await imageCaches.putCache(url.toString(), bytes,