flutter - 在 Firestore 中存储参考字符串
问题描述
我有一个名为 FoodModel.dart 的模型类,如果我试图引用文件,那么该文件将存储在 Firebase 存储中,它将具有指向存储的字符串路径。此路径将作为字符串存储在 Firestore 中。
class FoodModel{
final String? id;
final String? name;
@ImageConvertor()
final File? file;
const FoodModel({
required this.id,
this.name,
this.file})
}
这是Json转换器
class ImageConvertor implements JsonConverter<File?, String?> {
const ImageConvertor();
@override
File? fromJson(String? json) => File(json!);
@override
String? toJson(File? object) => object!.path;
}
但是模型不会转换为字符串到文件或文件到字符串。
当我尝试将其保存在 Firestore 中时抛出错误。无效参数:“FoodModel”实例
文件:'https:
解决方案
推荐阅读
- php - PHP登录表单不读取用户级别
- makefile - Makefile 在条件内扩展变量取决于定义的顺序
- netsuite - 套件脚本。如何从客户记录中检索主要联系人。如果类型是公司
- javascript - 捕捉承诺拒绝
- javascript - 如何在javascript中操作数组的值?
- c# - 在C#中填写openingstime的Combobox并停止直到delivery Time
- logstash-grok - 我可以有一个只有内部 id 和主机名的 grok 表达式吗?
- c# - 使用命名空间将类序列化为 XML
- typo3 - 在 TYPO3 V9 中用流体覆盖页面属性
- symfony - 错误代码 1 缓存:在作曲家要求期间清除