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



我已经在我的移动应用程序中实现了flutter_quill编辑器。所以我需要上传所有的图像到firebase存储,哪个用户从图库中挑选。但是这个动作应该在用户创建整个文档之后执行。

我使用这个方法来获取json文档,

Future<String> onUpload() async{ return jsonEncode(controller.document.toDelta().toJson()); }

然后我使用这个函数上传资产到firebase存储,

Future<String?> uploadAssetsToStore({filePath, folderName, fileName}) async{ return await StorageService().uploadFile(filePath, folderName, fileName); }'

我需要一个给出答案的代码

经过小实验,我得到了解决方案,

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);

}

最新更新