【发布时间】:2022-08-10 17:11:32
【问题描述】:
我没有在我的应用程序中看到我的图像,而是看到一个带有 X 的红色框,上面写着 Unable to load asset: images/aboutmaggie.png.
我创建了一个目录assets 和一个子目录images。目录assets 与pubspec.yaml 处于同一级别。
我将图像放入images 目录。当我在 Android Studio 中单击图像时,图像会显示。
在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/
我添加了
class AboutRoute extends StatelessWidget {
const AboutRoute({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(\'Kabbalistic Numerology\'),
),
body: ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(8),
children: <Widget>[
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: \'About Maggie McPherson\',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
)),
],
),
textAlign: TextAlign.center,
),
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text:
\"Dr. Leslie Margaret Perrin McPherson...\",
style: TextStyle(
color: Colors.black,
)),
],
),
),
Image.asset(\'images/aboutmaggie.png\'), // <--this image doesn\'t load
]));
}
}
我跑了flutter pub get。我运行了工具 > 颤振 > 颤振清洁。我关闭并重新启动了 Android Studio。
错误信息是:
======== Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: images/aboutmaggie.png
我尝试将另一个图像放入assets/images 并调用它,但第二个图像也不会加载。
这张图有什么问题?
标签: flutter