android-studio - 为什么不显示图像资产
问题描述
我想使用 Android Studio 在颤动中显示图像资产,但它没有显示在应用程序中,即使它占用空间
当我选择图像时,我使用了颤振检查器,它向我显示图像应该是白色方块。我已经在 pubsec.yaml 中添加了资产
图像资产代码
class CarsImage extends StatelessWidget{
@override
Widget build(BuildContext context) {
AssetImage carAsset = AssetImage('ímages/buga.png');
Image im = Image(image: carAsset,height: 250.0,width: 250.0,);
return im;
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return CarsImage()
;
}
pubsec.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:
- images/
我希望图像会出现。
解决方案
如果您在项目中名为“assets”的文件夹中添加了图像,并且在该文件夹中创建了名为“images”的文件夹,请尝试pubspec.yaml
按照以下方式在您的文件夹中定义它:
- assets/images/buga.png
之后,您可以按以下方式使用资产中的图像:
Image.asset('assets/images/buga.png')
推荐阅读
- java - 传递了错误的参数。爪哇
- javascript - 如何让 if/else 语句在函数内部工作
- sql-server - 授予创建数据库的访问权限,但不授予对现有数据库的访问权限
- kubernetes - 可以从 metrics-server 获取哪些指标用于 Horizontal Pod Autoscaling
- ios - Swift:使用 NSNotification 更新 Button.setTitle 和当前 UIPageView
- python - 如何使用列表操作字典并插入另一个字典
- html - 使用VBA从Excel中的网页中提取表格
- java - 当我们在类名中使用“iOS”作为单词时,我们应该将“i”大写吗?
- html - 在登录表单中制作下面的导航链接
- c++ - 理解 std::fmod 和 std::remainder