Flutter踩坑之-cached_network_image

  • Post author:
  • Post category:其他


运行项目报错如下:

Launching lib/main.dart on MHA AL00 in debug mode…

[!] Your app isn’t using AndroidX.

To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY.

Running Gradle task ‘assembleDebug’…

Compiler message:

../../../eclipseProject/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/cached_network_image-1.1.0/lib/src/cached_network_image_provider.dart:42:24: Error: The method ‘CachedNetworkImageProvider.load’ has fewer positional arguments than those of overridden method ‘ImageProvider.load’.

ImageStreamCompleter load(CachedNetworkImageProvider key) {


^


../../../eclipseProject/flutterSdk/flutter/packages/flutter/lib/src/painting/image_provider.dart:403:24: Context: This is the overridden method (‘load’).

ImageStreamCompleter load(T key, DecoderCallback decode);


^

Target kernel_snapshot failed: Exception: Errors during snapshot creation: null

build failed.

FAILURE: Build failed with an exception.

* Where:

Script ‘/Users/hello/Desktop/eclipseProject/flutterSdk/flutter/packages/flutter_tools/gradle/flutter.gradle’ line: 780

* What went wrong:

Execution failed for task ‘:app:compileFlutterBuildDebug’.

> Process ‘command ‘/Users/hello/Desktop/eclipseProject/flutterSdk/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 11s

Finished with error: Gradle task assembleDebug failed with exit code 1

注意标红部分,发现是由于cached_network_image版本低引起的,打开pubspec.yaml文件,修改cached_network_image版本从原来的 1.1.0修改为2.0.0-rc,然后点击Packages  get 完成后,重新运行,错误日志如下:

Running “flutter pub get” in FlutterDouBan…


Because cached_network_image 2.0.0-rc depends on flutter_cache_manager ^1.1.2 and doubanapp depends on flutter_cache_manager 1.1.0, cached_network_image 2.0.0-rc is forbidden.

So, because doubanapp depends on cached_network_image 2.0.0-rc, version solving failed.

pub get failed (1; So, because doubanapp depends on cached_network_image 2.0.0-rc, version solving failed.)

Process finished with exit code 1

可以看到cached_network_image版本更新后,与flutter_cache_manager版本起冲突,并且已经提示flutter_cache_manager版本更改1.1.2就可以了,修改之后,再次点击Packages get,顺利运行,OK



版权声明:本文为jwg1988原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。