Reputation: 129
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
Upvotes: 4
Views: 3964
Reputation: 111
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
Upvotes: 0
Reputation: 161
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);
Upvotes: 6
Reputation: 17776
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.
Upvotes: 0
Reputation: 852
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
});
Upvotes: 1