如何在flutter quill中用url-image代替file-image

rjee0c15  于 2022-12-27  发布在  Flutter
关注(0)|答案(1)|浏览(171)

我已经在我的移动的应用程序中实现了flutter_quill编辑器。所以我需要上传所有的图像到firebase存储,用户从图库中选择。但这个操作应该在用户创建整个文档后进行。
我使用这个方法来获取JSON文档,
第一个月
然后我使用这个函数将资产上传到firebase存储中,
Future<String?> uploadAssetsToStore({filePath, folderName, fileName}) async{ return await StorageService().uploadFile(filePath, folderName, fileName); }
我需要一个代码,这个问题给出了解决方案

y4ekin9u

y4ekin9u1#

我做了一个小小的实验,

Future<String> getFinalizedDoc() async{
var jsonPost = jsonDecode(widget.post);
for (var operation in jsonPost){
  if (operation['insert'] is Map && operation['insert'].containsKey('image') && operation['insert']['image'] != "" && !Uri.parse(operation['insert']['image']).isAbsolute) {
    String oldImagePath = await operation['insert']['image'];
    operation['insert']['image'] = await uploadAssetsToStore(
      filePath: File(oldImagePath),
      folderName: 'PostImages',
      fileName: path_delegate.basename(oldImagePath)
    );
  }
  else if (operation['insert'] is Map && operation['insert'].containsKey('video') && operation['insert']['video'] != "" && !Uri.parse(operation['insert']['video']).isAbsolute) {
    String oldVideoPath = await operation['insert']['video'];
    operation['insert']['video'] = await uploadAssetsToStore(
        filePath: File(oldVideoPath),
        folderName: 'PostVideos',
        fileName: path_delegate.basename(oldVideoPath)
    );
  }
}
return jsonEncode(jsonPost);

}

相关问题