flutter - 如何在flutter中将缓存的图像添加到应用栏(使用cached_image_network)
问题描述
return Scaffold(
appBar: AppBar(title: CachedNetworkImage(imageUrl: "https://cdn.pixabay.com/photo/2016/02/24/19/05/apples-1220574__340.png",
width: 80.0,
height: 80.0,
)),
我使用缓存的网络图像在颤振应用栏中添加图像但它不起作用请帮助
这是控制台错误
Compiler message:
../../AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/cached_network_image-1.1.2+1/lib/src/scaled_file_image.dart:45:24: Error: The method 'ScaledFileImage.load' has fewer positional arguments than those of overridden method 'ImageProvider.load'.
ImageStreamCompleter load(ScaledFileImage key) {
^
../../Flutter/packages/flutter/lib/src/painting/image_provider.dart:403:24: Context: This is the overridden method ('load').
ImageStreamCompleter load(T key, DecoderCallback decode);
^
../../AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/cached_network_image-1.1.2+1/lib/src/cached_network_image_provider.dart:53:24: Error: The method 'CachedNetworkImageProvider.load' has fewer positional arguments than those of overridden method 'ImageProvider.load'.
ImageStreamCompleter load(CachedNetworkImageProvider key) {
^
../../Flutter/packages/flutter/lib/src/painting/image_provider.dart:403:24: Context: This is the overridden method ('load').
ImageStreamCompleter load(T key, DecoderCallback decode);
^
Exception: Errors during snapshot creation: null
#0 KernelSnapshot.build (package:flutter_tools/src/build_system/targets/dart.dart:230:7)
<asynchronous suspension>
#1 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:526:25)
<asynchronous suspension>
#2 _BuildInstance.invokeTarget.<anonymous closure> (package:flutter_tools/src/build_system/build_system.dart:481:35)
#3 new Future.sync (dart:async/future.dart:222:31)
#4 AsyncMemoizer.runOnce (package:async/src/async_memoizer.dart:43:45)
#5 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:481:21)
<asynchronous suspension>
<asynchronous suspension>
#6 BuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:419:36)
#7 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6)
#8 BuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:400:28)
#9 buildWithAssemble (package:flutter_tools/src/bundle.dart:125:48)
#10 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6)
#11 buildWithAssemble (package:flutter_tools/src/bundle.dart:99:31)
#12 BundleBuilder.build (package:flutter_tools/src/bundle.dart:75:11)
#13 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6)
#14 BundleBuilder.build (package:flutter_tools/src/bundle.dart:52:21)
#15 BuildBundleCommand.runCommand (package:flutter_tools/src/commands/build_bundle.dart:126:25)
#16 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6)
#17 BuildBundleCommand.runCommand (package:flutter_tools/src/commands/build_bundle.dart:97:42)
#18 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:557:18)
#19 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:71:64)
#20 _rootRunUnary (dart:async/zone.dart:1132:38)
#21 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#22 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#23 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#24 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#25 Future._completeWithValue (dart:async/future_impl.dart:522:5)
#26 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:552:7)
#27 _rootRun (dart:async/zone.dart:1124:13)
#28 _CustomZone.run (dart:async/zone.dart:1021:19)
#29 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#30 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
#31 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#32 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#33 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#34 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
Failed to build bundle.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\user\Flutter\packages\flutter_tools\gradle\flutter.gradle' line: 794
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebugArm'.
> Process 'command 'C:\Users\user\Flutter\bin\flutter.bat'' finished with non-zero exit value 1
请帮我找到解决方案。我想将缓存的网络图像添加到我的应用程序中。你有更好的解决方案吗???
如果你想要完整的代码,请告诉我我使用缓存的网络图像在颤振应用栏中添加图像但它不起作用请帮助
解决方案
确保使用库的最新版本。就我而言,我尝试了下一个代码:cached_network_image: ^1.1.2
在我的中pubspec.yaml
,一切正常。
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'AppBar Demo',
debugShowCheckedModeBanner: false,
home: MyApp()
),
);
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: CachedNetworkImage(
imageUrl: "https://cdn.pixabay.com/photo/2016/02/24/19/05/apples-1220574__340.png",
width: 80.0,
height: 80.0,
)
),
body: Center(
child: Container(
child: Text("asd"),
),
),
);
}
}
推荐阅读
- java - 无法解析以下属性:复合键中属性的实体
- operating-system - 《操作系统概念》:忙等待不是用信号量消除的吗?
- ios - Expo / React-Native,有没有办法在设备/模拟器上测试运行独立的 iOS 应用程序?
- c# - 如何添加查询 LINQ 以从表中获取结果?
- api - GPS 不准确导致 Google 距离矩阵 API 返回错误的旅行持续时间
- javascript - 随着窗口大小的改变,缩放全屏画布以适应内容
- parceljs - 如何在 parceljs 中使用 env 构建
- python - 将python字节列表转换为字典
- java - 等到布尔值更改而不阻塞JavaFX主线程?
- javascript - 动态添加日期选择器