Flutter FireStore New Update Method #6114
Unanswered
Peng-Qian
asked this question in
Feature request
Replies: 1 comment 8 replies
-
I'm not sure about this but I think @freezed
class Person with _$Person {
factory Person({ String? name, int? age }) = _Person;
// ...
}
final personsRef = FirebaseFirestore.instance.collection('persons').withConverter<Person>(/** */);
void main() async {
final person = Person('foo', 22);
final personDoc = personsRef.doc();
await personDoc.set(person); // 1 write
// Update person
await personDoc.set(person.copyWith(age: 33)); // 1 write
} I think if you want the updating only specific fields behavior you can optionally add Maybe I'm not fully understanding your intention with |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Request
add new update method
Why
How
It is great for adding
withConverter()
in the new API, and since the Firestore instance know the converter, I think to create another update method to allow user pass old data and new data directly will be much nicer (like currentset()
method).It can automatically detect the difference and generate Map<String, dynamic> with FieldValue.delete().
or can firebase expose the converter to allow us adding dart extension to do that
Beta Was this translation helpful? Give feedback.
All reactions