使用Scaffold Class时,无法在Flutter应用程序上显示图像



我正在为一个简单的flutter应用程序编写代码。代码非常简单,

void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.teal,
shadowColor: Colors.black38,
title: Text(
'Some Ramdom Text',
style: TextStyle(color: Colors.black),
),
),
body: Center(
child: Image.asset('images/poor.png'),
),
),
),
);
}

然而,当我运行它时,我会得到以下错误:

The following assertion was thrown resolving an image codec:
Unable to load asset: images/poor.png
When the exception was thrown, this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224:7)
<asynchronous suspension>

我会错过什么?我试着重构这个项目。

我查了一下pubspec.yaml,它看起来不错。

assets:
- images/

错误声明自身It was not able to find the assets or load it在保存后在pubsec.yaml中执行pub-get。它将解决你的问题

我使用的是Android Studio,当我打开pubspec.yaml时,我在屏幕右上角看到Pub Get选项。

这使项目能够安装引用的包。

在此之后,我可以查看图像。

相关内容

最新更新