当我第一次在模拟器或真实设备上启动应用程序八时,出现此错误:
flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
flutter: The following assertion was thrown resolving an image codec:
flutter: Unable to load asset: assets/New alert button.png
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
flutter: <asynchronous suspension>
flutter: #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:484:44)
flutter: #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:469:14)
flutter: #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
flutter: #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
flutter: #5 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
flutter: (elided 13 frames from package dart:async)
flutter:
flutter: Image provider: AssetImage(bundle: null, name: "assets/New alert button.png")
flutter: Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#3cb5b(), name: "assets/New alert
flutter: button.png", scale: 1.0)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: Unable to load asset: assets/New route button.png
flutter: Another exception was thrown: Unable to load asset: assets/Center map button.png
阅读与该问题相关的其他帖子(不同的解决方案建议使用不同的方式)我尝试了不同的缩进,所以我都尝试了两种方法:
flutter:
uses-material-design: true
assets:
- assets/
和
flutter:
uses-material-design: true
assets:
- assets/
但没有任何变化。如果执行热重启,则将正确加载资产。 我遇到的另一个问题,或者可能是真正潜在问题的暗示,是如果我将图像从IDE拖放到资产文件夹中,则会出现错误:
这是使用资产的一个按钮:
IconButton(
icon: Image.asset('assets/Center map button.png'),
iconSize: 60,
onPressed: () {
print('Center map button pressed');
_mapController.move(userLocation, 16);
}),
峡谷发现我在做什么错? 一如既往,非常感谢您的时间和帮助。