[英]flutter doesn't show images in the web
Hello i have build a flutter web project which includes some images but all without one aren't shown in the web but all are shown in the emulator.您好,我已经构建了一个 flutter web 项目,其中包括一些图像,但没有一个没有显示在 web 中,但都显示在模拟器中。 Could you tell me the solution for this?
你能告诉我解决这个问题的方法吗? Tell me if you need more insides.
告诉我你是否需要更多的内脏。
pubspec.yaml: pubspec.yaml:
name: nanostifel
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
CFBundleVersion.
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:[enter image description here][1]
- images/
If you check the migration guide for Flutter Web you will see that: If the application has assets, they need to be in the web/assets directory.如果您查看Flutter Web 的迁移指南,您将看到:如果应用程序有资产,它们需要位于 web/assets 目录中。 You may also have to update paths within your source code that reference these assets.
您可能还必须更新源代码中引用这些资产的路径。
But for the latest versions of Flutter you can have the assets directory in the root of your project too.但是对于 Flutter 的最新版本,您也可以在项目的根目录中拥有 assets 目录。
So check this steps:所以检查这个步骤:
web/assets
of your project.web/assets
文件夹中。To use it in aa widget, you don't need to use all the path, use only the file name, for example if you have the image web/assets/myImage.png
just use it as follows:要在一个小部件中使用它,您不需要使用所有路径,只使用文件名,例如,如果您有图像
web/assets/myImage.png
,只需按如下方式使用它:
Image.asset('myImage.png')
And if you are working with the latest version of Flutter, and you have your image in a folder rootProject/assets/images/myImage.png
use it as follows:如果您使用的是最新版本的 Flutter,并且您的图像位于
rootProject/assets/images/myImage.png
文件夹中,请按如下方式使用它:
Image.asset('images/myImage.png')
In both cases is it necessary to have the images in a folder named assets
在这两种情况下,都必须将图像放在名为
assets
的文件夹中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.