web-dev-qa-db-ja.com

エラー:引数の型 'void Function(ImageInfo、bool)'をパラメーターの型 'ImageStreamListener'に割り当てることはできません

Flutter runをアップグレードした後、アプリが実行されません。 ImageStreamListenerのためアップグレードします

さまざまなチャネル[master、stable、dev]を変更しようとしましたが、機能しませんでした。

Flutterで this の問題が見つかりましたが、役に立ちませんでした。

これが私のflutter doctor

[✓] Flutter (Channel unknown, v1.7.11, on Mac OS X 10.14.5 18F132, locale en-PE)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] iOS tools - develop for iOS devices
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2019.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.36.0)
[✓] Connected device (3 available)

そしてエラーメッセージ

Compiler message:                                                       
file:///Users/enzoftware/Development/flutter/.pub-cache/hosted/pub.dartlang.org/palette_generator-0.1.1/lib/palette_generator.Dart:188:29: Error: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.Dart' ('file:///Users/enzoftware/Development/flutter/packages/flutter/lib/src/painting/image_stream.Dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.Dart' ('file:///Users/enzoftware/Development/flutter/packages/flutter/lib/src/painting/image_stream.Dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
      stream.removeListener(imageListener);                             
                            ^                                           
file:///Users/enzoftware/Development/flutter/.pub-cache/hosted/pub.dartlang.org/palette_generator-0.1.1/lib/palette_generator.Dart:194:31: Error: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.Dart' ('file:///Users/enzoftware/Development/flutter/packages/flutter/lib/src/painting/image_stream.Dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.Dart' ('file:///Users/enzoftware/Development/flutter/packages/flutter/lib/src/painting/image_stream.Dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
        stream.removeListener(imageListener);                           
                              ^                                         
file:///Users/enzoftware/Development/flutter/.pub-cache/hosted/pub.dartlang.org/palette_generator-0.1.1/lib/palette_generator.Dart:201:24: Error: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.Dart' ('file:///Users/enzoftware/Development/flutter/packages/flutter/lib/src/painting/image_stream.Dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.Dart' ('file:///Users/enzoftware/Development/flutter/packages/flutter/lib/src/painting/image_stream.Dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
    stream.addListener(imageListener);                                  
                       ^                                                
Compiler failed on /Users/enzoftware/Projects/Wibo/wibo-flutter-mobile-user/lib/main.Dart

FAILURE: Build failed with an exception.                                

* Where:                                                                
Script '/Users/enzoftware/Development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 652

* What went wrong:                                                      
Execution failed for task ':app:compileflutterBuildDebugArm'.           
> Process 'command '/Users/enzoftware/Development/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org                              

BUILD FAILED in 29s                                                     
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        29.7s
Gradle task assembleDebug failed with exit code 1

前もって感謝します。

9
Enzo Lizama

そのAPIには、最近の重大な変更がありました。

これは古い使用と新しい使用の例です

    // get the width, height
    Image image = new Image.file(myImageFile);
    Completer<ImageInfo> completer = Completer();

    // Old API
//    image.image
//        .resolve(new ImageConfiguration())
//        .addListener((ImageInfo info, bool _) {
//      completer.complete(info);
//    });

    // New API
    image.image
        .resolve(new ImageConfiguration())
        .addListener(ImageStreamListener((ImageInfo info, bool _) {
      completer.complete(info);
    }));

    // wait for ImageInfo to finish
    ImageInfo imageInfo = await completer.future;
6
aaronvargas

私はこれに数日間苦労し、その後、実験として、zoomable_imageからソースコードをコピーしてローカルファイルzoomable.Dartを作成し、問題のある行を編集しました。

_imageStream.addListener(_handleImageLoaded);
_imageStream.removeListener(_handleImageLoaded);

_imageStream.addListener(ImageStreamListener(_handleImageLoaded));
_imageStream.removeListener(ImageStreamListener(_handleImageLoaded));

私はgitファイルをチェックアウトしてgitの初心者であることを修正する能力がないと感じています。所有者はこれを行うべきではありませんか?

4
Scott Anthony

私は下のリンクから解決策を得ました:

https://github.com/renefloor/flutter_cached_network_image/issues/197

this._networkImage.image.resolve(ImageConfiguration()).addListener(
            ImageStreamListener((ImageInfo image, bool synchronousCall) {
          if (mounted)
            setState(() => this._imageDownloadState = ImageDownloadState.Done);
        }));

そして、firebase_storage_image.Dartファイルを使用している人は、主にこの問題が発生します。上記のコードはそのために機能します。

https://Gist.github.com/jeroen-meijer/f0996dd35065c17ac79eeb3938bc89e4

0
Mahesh Peri