android - 无法在颤动中加载图像资产
问题描述
嗨,我一直在尝试将此图像加载为我的背景,但每当我尝试调试和运行我的应用程序时,就会发生此异常。在下面我尝试过缩进,但是当我尝试运行 image_provide.dart 文件打开并在调试控制台中出现此错误时,问题仍然存在,此应用程序是登录 UI,请清除它。我是颤振初学者,所以全心全意接受批评
════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assetimagesclock.png
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:227
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync
package:flutter/…/painting/image_provider.dart:675
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "assetimagesclock.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#9c9b1(), name: "assetimagesclock.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════
这是我的 main.dart
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(home: new MyApp()),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
child: Column(
children: <Widget>[
Container(
height: 400,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset\images\clock.png'),
fit: BoxFit.fill),
),
)
],
)),
),
);
}
}
这是我的 pubspec.yaml 文件
name: login_ui
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
simple_animations: ^1.3.3
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
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/
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
解决方案
我认为您的 pubspec.yaml 似乎工作正常。但是你在下面这行打错了:AssetImage(' asset \images\clock.png'),替换为:AssetImage(' assets \images\clock.png'),
推荐阅读
- c - 为什么我不能将一个数组复制到另一个数组?
- java - 如何解决android电子邮件意图问题?
- linux - envsubst 仅适用于部分变量
- c# - 如何将双精度值从 html 输入传递到 C# 控制器
- sqlite - QT SQLite 无法获取表信息
- tensorflow - 如何将低级代码从 TF 1 转换为 TF 2
- scala - 为什么我必须传递 new 关键字?
- angular - 有条件地链接多个 observables 的更简洁的方法
- vue.js - 使用 Webpack 4 在 Phoenix 1.4 应用程序中安装 Vue 2
- asp.net-web-api - System.InvalidOperationException(An exception was thrown while attempting to evaluate a LINQ query parameter expression)