saveToAlbum static method

Future<AssetEntity?> saveToAlbum(
  1. {String? url,
  2. AssetEntity? asset,
  3. String? base64Img,
  4. Uint8List? uint8list,
  5. String? path}
)

保存图片到相册

url 网络图片 asset AssetEntity 资源文件 base64Img Base64 图片 uint8list then Uint8List type path 本地文件路径

Implementation

static Future<AssetEntity?> saveToAlbum(
    {String? url, AssetEntity? asset, String? base64Img, Uint8List? uint8list, String? path}) async {
  if (uint8list != null) {
    return await PhotoManager.editor.saveImage(uint8list);
  } else if (base64Img != null) {
    final Uint8List bytes = base64.decode(base64Img);
    return await PhotoManager.editor.saveImage(bytes);
  } else if (asset != null) {
    return asset.saveToAlbum();
  } else if (path != null) {
    final File file = File(path);
    final Uint8List byteData = await file.readAsBytes();
    return await PhotoManager.editor.saveImage(byteData);
  } else if (url != null) {
    final Uint8List? data = await getNetworkImageData(url, useCache: false);
    if (data != null) {
      return await PhotoManager.editor.saveImage(data);
    }
  }
  return Future.value(null);
}