I am updating my old flutter code with the new FlutterFire API. I use a setData
with merge: true
in one of my functions to update some document fields that are saved in a Map. I do change setData
to set
, but I get an error with the new FlutterFire plugin that "merge" isn't defined. I found in the migration docs that
setData/set now supports SetOptions to merge data/fields (previously this accepted a Map)
The document reference also says:
/// If [SetOptions] are provided, the data will be merged into an existing
/// document instead of overwriting.
Future<void> set(Map<String, dynamic> data, [SetOptions options]) {
assert(data != null);
return _delegate.set(
_CodecUtility.replaceValueWithDelegatesInMap(data), options);
}
In my original code, I am saving new values in a Map<String, dynamic>
called changedvalues
and then I use setData(changedValues, merge:true)
So, How do I provide SetOptions to make sure merge is true and only the fields in the changedValues are updated in the document?
You have to do the following:
set({"name" : "akbarB"}, SetOptions(merge : true))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With