错误:无法将参数类型“ void Function(ImageInfo,bool)”分配给参数类型“ ImageStreamListener”

Enz*_*ama 7 android dart flutter flutter-dependencies

升级Flutter Run之后,该应用程序将无法运行。我升级是因为ImageStreamListener

我试图在不同的渠道[主要,稳定,开发]上进行更改,但没有工作。

我在Flutter中发现了问题,但没有帮助。

这是我的 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)
Run Code Online (Sandbox Code Playgroud)

和错误消息

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
Run Code Online (Sandbox Code Playgroud)

提前致谢。

小智 6

我为此苦苦挣扎了几天,然后作为实验,从 zoomable_image 复制了源代码并创建了一个本地文件 zoomable.dart 并编辑了违规行:

_imageStream.addListener(_handleImageLoaded);
_imageStream.removeListener(_handleImageLoaded);
Run Code Online (Sandbox Code Playgroud)

_imageStream.addListener(ImageStreamListener(_handleImageLoaded));
_imageStream.removeListener(ImageStreamListener(_handleImageLoaded));
Run Code Online (Sandbox Code Playgroud)

作为 git 的新手,我觉得没有能力检查 git 文件并修复它。楼主不应该这样做吗?


aar*_*gas 5

该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;
Run Code Online (Sandbox Code Playgroud)