[英]How to add flutter image from local folder stored in assets
I have Stored local images in assets/images file added the pubspcs.yml also我在资产/图像文件中存储了本地图像,还添加了 pubspcs.yml
assets: - Assets/images/ but i am fetching values from another dummy.dart file like this assets: - Assets/images/ 但我正在从另一个 dummy.dart 文件中获取值,就像这样
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(title: Text(categoryTitle)),
body: ListView.builder(
itemBuilder: (ctx, index) {
return MealItem(
id: displayedMeals[index].id,
title: displayedMeals[index].title,
**imageUrl: displayedMeals[index].imageUrl,**
duration: displayedMeals[index].duration,
affordability: displayedMeals[index].affordability,
complexity: displayedMeals[index].complexity,
// removeItem: _removeMeal,
);
/* Text(categoryMeals[index].title) */;
},
itemCount: displayedMeals.length,
)
);
and I want the image to come with this index file which i am fetching from dummy.dart我希望图像附带我从 dummy.dart 获取的索引文件
imageUrl:
'https://www.whiskaffair.com/wp-content/uploads/2018/02/Hyderabadi-Mutton-Biryani-6.jpg',
instead of this i want from the image from assets/images
folder而不是这个我想从
assets/images
文件夹中的图像
You can use an asset image as default image.您可以使用资产图像作为默认图像。
child: new Container(
child: FadeInImage.assetNetwork(
placeholder: 'place_holder.jpg',
image:url
)
)
Put this in pubspec.yaml把这个放在 pubspec.yaml
assets:
- assets/place_holder.jpg
Images are resolved using ImageProvider
.图像使用
ImageProvider
解析。
There is a bunch of concrete implementations for different sources of images: FileImage
, AssetImage
, NetworkImage
, MemoryImage
, etc. Also there is associated factory constructors on Image
class.对于不同的图像来源有一堆具体的实现:
FileImage
、 AssetImage
、 NetworkImage
、 MemoryImage
等Image
class 上还有相关的工厂构造函数。
Probably you have something similar in MealItem
:可能您在
MealItem
中有类似的东西:
Image.network(imageUrl)
You could either use ImageProvider
:您可以使用
ImageProvider
:
Image(image: imageProvider)
Or directly provide Image
widget in constructor.或者直接在构造函数中提供
Image
小部件。
Anyway you should know the source of the image to use appropriate ImageProvider
implementation or Image
constructor.无论如何,您应该知道图像的来源以使用适当的
ImageProvider
实现或Image
构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.