From fc0ab443e9b8498b67a443b0a7c24bb5dbb561c6 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Tue, 27 Sep 2022 11:53:58 +0200 Subject: [PATCH] remove redundant code from ssh image provider --- lib/data_provider/ssh_data_provider.dart | 40 ++++++------------------ lib/home_page.dart | 13 ++------ 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/lib/data_provider/ssh_data_provider.dart b/lib/data_provider/ssh_data_provider.dart index 62daa31..f8eb9c5 100644 --- a/lib/data_provider/ssh_data_provider.dart +++ b/lib/data_provider/ssh_data_provider.dart @@ -73,37 +73,22 @@ class SSHDataProvider extends DataProvider { } class _SSHImageProvider extends ImageProvider<_SSHImageProvider> { - const _SSHImageProvider(this.uri, this.sftpClient, {this.scale = 1.0}); + const _SSHImageProvider(this.uri, this.sftpClient); final Uri uri; final SftpClient sftpClient; - /// The scale to place in the [ImageInfo] object of the image. - final double scale; - @override Future<_SSHImageProvider> obtainKey(ImageConfiguration configuration) { return SynchronousFuture<_SSHImageProvider>(this); } - @override - ImageStreamCompleter load(_SSHImageProvider key, DecoderCallback decode) { - return MultiFrameImageStreamCompleter( - codec: _loadAsync(key, null, decode), - scale: key.scale, - debugLabel: key.uri.path, - informationCollector: () => [ - ErrorDescription('Path: ${uri.path}'), - ], - ); - } - @override ImageStreamCompleter loadBuffer( _SSHImageProvider key, DecoderBufferCallback decode) { return MultiFrameImageStreamCompleter( - codec: _loadAsync(key, decode, null), - scale: key.scale, + codec: _loadAsync(key, decode), + scale: 1.0, debugLabel: key.uri.path, informationCollector: () => [ ErrorDescription('Path: ${uri.path}'), @@ -111,8 +96,8 @@ class _SSHImageProvider extends ImageProvider<_SSHImageProvider> { ); } - Future _loadAsync(_SSHImageProvider key, - DecoderBufferCallback? decode, DecoderCallback? decodeDeprecated) async { + Future _loadAsync( + _SSHImageProvider key, DecoderBufferCallback decode) async { assert(key == this); Directory tempDir = await getTemporaryDirectory(); @@ -125,7 +110,6 @@ class _SSHImageProvider extends ImageProvider<_SSHImageProvider> { bytes = await tmpPic.readAsBytes(); } else { final file = await sftpClient.open(uri.toFilePath()); - // todo do not load whole image in ram, create tempfile instead. bytes = await file.readBytes(); await tmpPic.create(recursive: true); await tmpPic.writeAsBytes(bytes); @@ -138,10 +122,7 @@ class _SSHImageProvider extends ImageProvider<_SSHImageProvider> { 'bytes are empty is empty and cannot be loaded as an image.'); } - if (decode != null) { - return decode(await ui.ImmutableBuffer.fromUint8List(bytes)); - } - return decodeDeprecated!(bytes); + return decode(await ui.ImmutableBuffer.fromUint8List(bytes)); } @override @@ -149,15 +130,12 @@ class _SSHImageProvider extends ImageProvider<_SSHImageProvider> { if (other.runtimeType != runtimeType) { return false; } - return other is _SSHImageProvider && - other.uri.path == uri.path && - other.scale == scale; + return other is _SSHImageProvider && other.uri.path == uri.path; } @override - int get hashCode => Object.hash(uri.path, scale); + int get hashCode => uri.path.hashCode; @override - String toString() => - '${objectRuntimeType(this, 'FileImage')}("${uri.path}", scale: $scale)'; + String toString() => '${objectRuntimeType(this, 'FileImage')}("${uri.path}")'; } diff --git a/lib/home_page.dart b/lib/home_page.dart index 32521de..e4a3df0 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,9 +1,8 @@ import 'package:flutter/material.dart'; import 'package:gallery/data_provider/data_provider.dart'; -import 'package:gallery/data_provider/local_data_provider.dart'; -import 'package:gallery/data_provider/ssh_data_provider.dart'; import 'package:gallery/image_tile.dart'; +import 'data_provider/local_data_provider.dart'; import 'full_screen_image_view.dart'; class MyHomePage extends StatefulWidget { @@ -18,15 +17,7 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { Future? folder; - // DataProvider dprovider = SSHDataProvider( - // initialPath: "/media/", - // host: "", - // password: "", - // port: 22, - // username: ""); - - // DataProvider dprovider = LocalDataProvider("${(await getApplicationDocumentsDirectory()).path}/../Downloads/"); - DataProvider dprovider = LocalDataProvider("/home"); + final DataProvider dprovider = LocalDataProvider("/home"); final ScrollController _controller = ScrollController();