我的项目运行良好,就在今天,我已经升级了Flutter
,然后一切开始运行。
最底层的是他们给我的错误。 请帮助我。
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
答案 0 :(得分:1)
通过替换解决了类似的问题
/*...*/.addListener((ImageInfo image, bool synchronousCall) { /*...*/ });
使用
import 'package:flutter/painting.dart';
/*...*/.addListener(new ImageStreamListener((ImageInfo image, bool synchronousCall) { /*...*/ }) as ImageStreamListener);
答案 1 :(得分:0)
我遇到了同样的问题,这里只是一些示例代码
破解代码:
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);
});
});
}
代码在load.addListener((listener, err) async { ....
行上中断
我解决了创建一个ImageListener
函数的问题,该函数与我以前使用listener
变量的函数相同。然后创建一个ImageStreamListener
来接收此ImageListener
作为参数。还要注意,您可以将参数onError
和onChunk
发送到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
});
答案 2 :(得分:0)
将animated_background
文件中的pubspec.yaml
依赖项更改为以下内容:
animated_background:
git: https://github.com/AndreBaltazar8/flutter_animated_background.git
随后执行flutter clean
并重建。
原因:之所以发生这种情况,是因为该依赖关系实际上已经在存储库中进行了更改,以匹配与Image API相关的某些框架更改,但在pub.dev中却没有。
答案 3 :(得分:0)
在Flutter打印插件中遇到ImageStreamListener错误。我正在使用Flutter 1.5.4修补程序2版本。
使用打印:2.0.2#修复此版本以解决ImageStreamListener问题。
希望有帮助