Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 将参数传递给withConverter方法cloud\u firestore 2.1.0的最佳方法_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Flutter 将参数传递给withConverter方法cloud\u firestore 2.1.0的最佳方法

Flutter 将参数传递给withConverter方法cloud\u firestore 2.1.0的最佳方法,flutter,dart,google-cloud-firestore,Flutter,Dart,Google Cloud Firestore,您好,我正在尝试迁移到cloud\u firestore 2.10,文档中说要这样实现: final modelsRef = FirebaseFirestore .instance .collection('models') .withConverter<Model>( fromFirestore: (snapshot, _) => Model.fromJson(snapshot.data()!), toFirestor

您好,我正在尝试迁移到
cloud\u firestore 2.10
,文档中说要这样实现:

final modelsRef = FirebaseFirestore
     .instance
     .collection('models')
     .withConverter<Model>(
       fromFirestore: (snapshot, _) => Model.fromJson(snapshot.data()!),
       toFirestore: (model, _) => model.toJson(),
     );

 Future<void> main() async {
   // Writes now take a Model as parameter instead of a Map
   await modelsRef.add(Model());
   final Model model = await modelsRef.doc('123').get().then((s) => s.data());
 }
final modelsRef=FirebaseFirestore
.例如
.collection('模型')
.带转换器(
fromFirestore:(快照,)=>Model.fromJson(snapshot.data()!),
toFirestore:(model,)=>model.toJson(),
);
Future main()异步{
//写入现在将模型作为参数,而不是映射
等待modelsRef.add(Model());
最终模型=等待模型ref.doc('123').get()。然后((s)=>s.data());
}
但是在我的例子中,我将参数传递给我的模型,而不仅仅是
Model.fromJson(snapshot.data()!)
我使用的示例是
GeneralProductModel.fromMap(snap.data()!,parameter1,parameter2),

最好的办法是什么?要使用
方法
而不是
final modelRef=

但是如果我将not
null
参数传递给该方法,并且仅在读取时需要它,而在写入时不需要它

提前谢谢