gpt4 book ai didi

android-studio - 为什么不显示图片资源

转载 作者:IT王子 更新时间:2023-10-29 07:08:10 24 4
gpt4 key购买 nike

我想使用 Android Studio 在 flutter 中显示图像资源,但它没有出现在应用程序中,即使它占用空间

当我选择图像时,我使用了 flutter inspector,它向我显示了图像应该出现的白色方 block 。我已经在 pubsec.yaml 中添加了 Assets

图片 Assets 代码

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

之后,您可以按照以下方式使用 Assets 中的图像:

Image.asset('assets/images/buga.png')

关于android-studio - 为什么不显示图片资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56927097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com