save method
Add/Update an element of document.
Implementation
@override
Future<void> save() async {
await FirebaseCore.initialize();
final firestore = FirebaseFirestore.instance;
await firestore.runTransaction((transaction) async {
try {
final doc = <String, dynamic>{
..._additionalData,
Const.uid: documentPath.split("/").last,
Const.time: FieldValue.serverTimestamp(),
};
doc.addAll(
_buildCounterUpdate(
key: _counterKey,
value: _counterValue,
enabled: _enableCounter,
counterIntervals: _counterIntervals ?? [],
),
);
transaction.set(
firestore.doc(documentPath),
doc,
SetOptions(merge: true),
);
} catch (e) {
print(e.toString());
rethrow;
}
});
}