remove redundant code from ssh image provider
This commit is contained in:
parent
84d34336ca
commit
fc0ab443e9
@ -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: () => <DiagnosticsNode>[
|
||||
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: () => <DiagnosticsNode>[
|
||||
ErrorDescription('Path: ${uri.path}'),
|
||||
@ -111,8 +96,8 @@ class _SSHImageProvider extends ImageProvider<_SSHImageProvider> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<ui.Codec> _loadAsync(_SSHImageProvider key,
|
||||
DecoderBufferCallback? decode, DecoderCallback? decodeDeprecated) async {
|
||||
Future<ui.Codec> _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,26 +122,20 @@ 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);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
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}")';
|
||||
}
|
||||
|
@ -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<MyHomePage> {
|
||||
Future<Folder>? 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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user