remove redundant code from ssh image provider
This commit is contained in:
		@@ -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,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}")';
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user