Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 无法加载资源映像_Image_Flutter - Fatal编程技术网

Image 无法加载资源映像

Image 无法加载资源映像,image,flutter,Image,Flutter,我想做一个简单的颤振应用程序,并想从我的资产添加一个图像,我已经尝试,但图像仍然无法加载。 这就是我加载图像的方式 Image.asset('assets/images/food.jpg') pubspec.yaml代码: flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons

我想做一个简单的颤振应用程序,并想从我的资产添加一个图像,我已经尝试,但图像仍然无法加载。 这就是我加载图像的方式

Image.asset('assets/images/food.jpg')

pubspec.yaml代码:

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
assets:
  - assets/images/food.jpg
调试:

I/flutter (18975): The following assertion was thrown resolving an image codec:
I/flutter (18975): Unable to load asset: assets/images/food.jpg
I/flutter (18975): Unable to load asset: assets/images/food.jpg
I/flutter (18975):
I/flutter (18975): When the exception was thrown, this was the stack:
I/flutter (18975): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (18975): <asynchronous suspension>
I/flutter (18975): #1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:433:44)
I/flutter (18975): <asynchronous suspension>
I/flutter (18975): #2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:418:14)
I/flutter (18975): #3      ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:105)
I/flutter (18975): #4      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:157:22)
I/flutter (18975): #5      ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:82)
I/flutter (18975): (elided 13 frames from package dart:async)
I/flutter (18975):
I/flutter (18975): Image provider: AssetImage(bundle: null, name: "assets/images/food.jpg")
I/flutter (18975): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#df91c(), name: "assets/images/food.jpg",
I/flutter (18975): scale: 1.0)
I/flatter(18975):解析图像编解码器时抛出以下断言:
I/flatter(18975):无法加载资产:资产/images/food.jpg
I/flatter(18975):无法加载资产:资产/images/food.jpg
I/颤振(18975):
I/flatter(18975):当抛出异常时,这是堆栈:
I/颤振(18975):#0平台组装包.load(包:颤振/src/services/asset_bundle.dart:221:7)

I/flatter(18975):

您的格式不符合pubspec.yaml的要求。您必须添加一个选项卡,因为它可以从代码中看到

像这样:

flutter:
   assets:
   - graphics/background.png
更多细节请看这个。