Hi I am trying to migrate to cloud_firestore 2.10
and the documentation https://pub.dev/packages/cloud_firestore/changelog says to implement like this:
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());
}
But I pass parameters to my models in my case instead of only Model.fromJson(snapshot.data()!)
I use for example GeneralProductModel.fromMap(snap.data()!, parameter1, parameter2),
What is the best aproach for this? to use a method
instead of final modelRef =
?
But if I pass a not null
parameter to the method and I only require it for example at read and not at write?
Thanks in advance!