英文:
unable load image asset in flutter
问题
我不确定为什么我的来自资产的图像无法正常工作。
我查看了这两个问题:
-
https://stackoverflow.com/questions/64158543/flutter-unable-to-load-image-asset
-
https://stackoverflow.com/questions/67552389/unable-to-load-image-asset
这是我尝试获取图像的方式:
Image(
image: AssetImage('assets/logo.png'),
width: 100,
height: 100,
),
这是我的pubspec.yaml
:
assets:
- assets/logo.png
- assets/back.png
以下是文件结构:
这是文件结构
我尝试按照YouTube上的视频操作,但那并没有起作用。
欢迎任何建议。
英文:
I am not sure why my images from assets is not working
I looked at these two questions:
-https://stackoverflow.com/questions/64158543/flutter-unable-to-load-image-asset
-https://stackoverflow.com/questions/67552389/unable-to-load-image-asset
this is how I am trying to fetch the image:
Image(
image: AssetImage('assets/logo.png'),
width: 100,
height: 100,
),
here is my pubspec.yaml
assets:
- assets/logo.png
- assets/back.png
I tried following videos on youtube but that didnt work.
any suggestions are welcome
答案1
得分: 1
尝试以下代码并更改您的 pubspec.yaml
文件如下-
如果您的图像在图像文件夹中
assets:
- assets/images
如果您的图像在资产文件夹中
assets:
- assets/
之后运行命令 flutter pub get
并停止代码,然后重新运行
英文:
Try below code and change your pubspec.yaml
file like-
if your images in images folder
assets:
- assets/images
if your images in assetsfolder
assets:
- assets/
after that run command flutter pub get
and Stop the code and re-run again
Refer assets-and-images
答案2
得分: 1
assets:
- assets/images/
Image(
image: AssetImage('assets/images/logo.png'),
width: 100,
height: 100,
),
英文:
if your images are in images folder of assets folder then declare as below in pubspec.yaml
assets:
- assets/images/
And write code to get image as below
Image(
image: AssetImage('assets/images/logo.png'),
width: 100,
height: 100,
),
答案3
得分: -1
我重新启动了应用程序,然后一切正常。
英文:
I ended up restarting the app then everyting worked
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论