Flutter 使用Scaffold类时无法在颤振应用程序上显示图像
我正在为一个简单的颤振应用程序编写代码。 代码非常简单Flutter 使用Scaffold类时无法在颤振应用程序上显示图像,flutter,Flutter,我正在为一个简单的颤振应用程序编写代码。 代码非常简单 void main() { runApp( MaterialApp( home: Scaffold( appBar: AppBar( backgroundColor: Colors.teal, shadowColor: Colors.black38, title: Text( 'Some Ramdom Text',
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>
我使用的是Android Studio,当我打开pubspec.yaml时,我会在屏幕右上角看到Pub Get选项 这使项目能够安装引用的软件包
在此之后,我可以查看图像。错误状态本身
它无法找到资产或加载资产
保存后在pubsec.yaml中执行pub get。
它会解决你的问题
assets:
- images/