首页 > 解决方案 > 如何在颤动中将图像网址转换为资产?

问题描述

我使用 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,
    );
  }),
);

标签: flutterdart

解决方案


您不能将数据放入资产中,因为它是与您的应用程序捆绑和部署的文件,并且可以在运行时访问。您可以将其存储在数据库中或将其转换为 Uint8list。


推荐阅读