4

My project was working perfectly and Just today i have upgrade my Flutter then everything start going run.

At the bottom is the error they give me. Please help me.

file:///Users/macbook/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/animated_background-1.0.4/lib/image_helper.dart:17:30: Error: The argument type 'dynamic Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
    newStream.removeListener(listener);
                             ^
file:///Users/macbook/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/animated_background-1.0.4/lib/image_helper.dart:20:25: Error: The argument type 'dynamic Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
  newStream.addListener(listener);
                        ^
file:///Users/macbook/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/animated_background-1.0.4/lib/image_helper.dart:21:41: Error: The argument type 'dynamic Function(ImageInfo, bool)' can't be assigned to the parameter type 'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart' ('file:///Users/macbook/Documents/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
  return () => newStream.removeListener(listener);
                                        ^
Compiler failed on /Users/macbook/AndroidStudioProjects/alimmentation/lib/main.dart
Finished with error: Gradle task assembleDebug failed with exit code 1
9
  • 1
    Have you tried flutter clean? Maybe that'll work? Also perhaps post the output of flutter doctor and flutter run -v.... Also make sure you have the latest flutter SDK and check out this thread just came across it github.com/flutter/flutter/issues/24645 Commented May 31, 2019 at 20:18
  • Here is my flutter doctor flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, v1.6.3, on Mac OS X 10.14.4 18E226, locale fr-BF) [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [✓] iOS toolchain - develop for iOS devices (Xcode 10.2) [✓] Android Studio (version 3.4) [✓] VS Code (version 1.34.0) [✓] Connected device (1 available) • No issues found! Commented May 31, 2019 at 20:19
  • Perhaps post it in the question next time but good to know there are no issues Commented May 31, 2019 at 20:21
  • @JoeA Thanks For sure new time I'll do it. Is there any solution? Commented May 31, 2019 at 20:29
  • 1
    Why do you not just fix the code? It clearly says what the problem is and upgrading the framework can introduce breaking changes. Commented May 31, 2019 at 20:32

4 Answers 4

6

Solved a similar issue by replacing

/*...*/.addListener((ImageInfo image, bool synchronousCall) { /*...*/ });

with

import 'package:flutter/painting.dart';

/*...*/.addListener(new ImageStreamListener((ImageInfo image, bool synchronousCall) { /*...*/ }) as ImageStreamListener);
1

I had the same problem, here is some code only as an example

Code that broke:

var sunImage = new NetworkImage(incident.mobileSignature[0].uriFile,
          headers: AuthenticationService.getAuthHeaders());
sunImage.obtainKey(new ImageConfiguration()).then((val) {
    var load = sunImage.load(val);
    load.addListener((listener, err) async {
        ByteData data = await listener.image.toByteData(format:ui.ImageByteFormat.png);
        setState(() => this.signatureImage = data);
    });
  });
}

The code broke on line load.addListener((listener, err) async { ....

I solved creating an ImageListener function that does the same as my previous function with the listener variable. And then create an ImageStreamListener that receives this ImageListener as parameter. Note also that you can send as parameters onError and onChunk to the ImageStreamListener.

var sunImage = new NetworkImage(incident.mobileSignature[0].uriFile,
          headers: AuthenticationService.getAuthHeaders());
sunImage.obtainKey(new ImageConfiguration()).then((val) {
    var load = sunImage.load(val);
    ImageListener imageListener = (ImageInfo imageInfo, syncCall) async {
        ByteData data =
              await imageInfo.image.toByteData(format: ui.ImageByteFormat.png);
          setState(() => this.signatureImage = data);
    };
    ImageStreamListener listenerStream = new ImageStreamListener(imageListener);
    load.addListener(listenerStream, onError: ...., onChunk: ......); // These last parameters are optional
});
0

Change your animated_background dependency in the pubspec.yaml file to the following:

animated_background:
    git: https://github.com/AndreBaltazar8/flutter_animated_background.git

Do a flutter clean afterwards and rebuild.

Reason: That happens because that dependency has actually been changed in the repo to match some of the framework changes related to the Image API, but not in the pub.dev.

0

Facing ImageStreamListener error in flutter printing plugin. I am using flutter 1.5.4 hotfix 2 version.

Use printing: 2.0.2 # fix it at this version to solve ImageStreamListener issue.

Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.