我是flutter应用程序开发的新手,并尝试在应用程序中显示和图像是我运行应用程序和我的代码片段时遇到的错误,请帮助新手。
Launching lib/main.dart on iPhone XR in debug mode...
Running Xcode build...
Xcode build done. 21.3s
Syncing files to device iPhone XR...
flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
flutter: The following assertion was thrown resolving an image codec:
flutter: Unable to load asset: assets/images/GEJ.jpg
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:433:44)
flutter: <asynchronous suspension>
flutter: #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:418:14)
flutter: #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:105)
flutter: #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:157:22)
flutter: #5 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:82)
flutter: (elided 13 frames from package dart:async)
flutter:
flutter: Image provider: AssetImage(bundle: null, name: "assets/images/GEJ.jpg")
flutter: Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#266bb(), name: "assets/images/GEJ.jpg",
flutter: scale: 1.0)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
代码段:
child: Image.asset(
'assets/images/GEJ.jpg',
fit: BoxFit.cover,
),
ps:以下是我的pubspec.yaml
信息:
environment: sdk: ">=2.1.0 <3.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^0.1.2 dev_dependencies: flutter_test: sdk: flutter flutter: assets: - assets/images/GEJ.jpg
当我缩进资产时:再说一张,它说资产不存在
您需要在assets
文件夹中制作称为images
的新文件夹,并在其中包含图像文件。这样:
com.yourpackage.app
- assets
- images
- GEJ.jpg
完成后,您需要在终端窗口中运行flutter packages get
命令,也可以使用读取Packages get
的IDE选项,当您在pubspec.yaml
文件中