flutter - 如何在颤动中将图像网址转换为资产?
问题描述
我使用 multi_image_picker 包从图库中获取图像。现在我想实现编辑页面,我需要将我的图像 url 列表转换为资产并将资产列表设置为 multi_image_picker。这是我的多图像选择器:
List<Asset> resultList = <Asset>[];
String error = 'No Error Detected';
try {
resultList = await MultiImagePicker.pickImages(
maxImages: 300,
enableCamera: true,
selectedAssets: _imagesAssets,
cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
materialOptions: MaterialOptions(
actionBarColor: "#abcdef",
actionBarTitle: "صندوق شهدای موردک",
allViewTitle: "تمام تصاویر",
useDetailsView: false,
selectCircleStrokeColor: "#000000",
),
);
} on Exception catch (e) {
error = e.toString();
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_imagesAssets = resultList;
});
}
和一个网格视图来显示选定的图像:
return GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.all(10),
children: List.generate(_imagesAssets.length, (index) {
Asset asset = _imagesAssets[index];
return AssetThumb(
asset: asset,
width: 100,
height: 100,
);
}),
);
解决方案
您不能将数据放入资产中,因为它是与您的应用程序捆绑和部署的文件,并且可以在运行时访问。您可以将其存储在数据库中或将其转换为 Uint8list。
推荐阅读
- c++ - 基于模板类构建
- reactjs - 使用到达路由器识别初始登录页面
- java - 如何从榛树地图中获取随机键值
- python - 带有嵌入式 Python 的 C++:Onnxruntime 模块在发布时已成功导入,但在调试时出现错误
- web - Firefox 82:重定向时网站图标损坏
- amazon-web-services - 仅在 VPN 连接上限制 Amazon S3 访问
- powershell - 如何在powershell中将chrome驱动程序版本输出为字符串?
- javascript - 生成器在 React 中的调用次数超出预期
- entity-framework-core - AspNetBoilerplate 实体上删除审核所有属性更改
- python - 我正在尝试使用 python 请求抓取一个网站,当单击加载时不会更改其链接,我尝试了更多但看起来它的 json