diff --git a/lib/src/App.dart b/lib/src/App.dart index 47df073..b27a305 100644 --- a/lib/src/App.dart +++ b/lib/src/App.dart @@ -7,7 +7,6 @@ import './resources/firestore_provider.dart'; class App extends StatelessWidget { Widget build(BuildContext context) { - final fire = FirestoreProvider(); return MaterialApp( title: 'Do more', //home: Text('Start'), diff --git a/lib/src/resources/firestore_provider.dart b/lib/src/resources/firestore_provider.dart index e90a2ee..078f277 100644 --- a/lib/src/resources/firestore_provider.dart +++ b/lib/src/resources/firestore_provider.dart @@ -84,7 +84,8 @@ class FirestoreProvider { /// Updates a task in firestore. /// /// Only the [text], [priority] and [done] attributes can be update. - /// Provide at least one of these values. + /// Provide at least one of these values or this operation won't have any + /// effect. Future updateTask( String id, { String text, @@ -97,6 +98,12 @@ class FirestoreProvider { 'done': done, }; newData.removeWhere((key, value) => value == null); + + // No need to call firestore if there's no new data to update. + if (newData.isEmpty) { + return; + } + try { final documentReference = firestore.collection('tasks').document(id); await documentReference.setData(newData, merge: true); @@ -166,6 +173,9 @@ class FirestoreProvider { return Observable(mappedStream); } + /// Deletes an event from firestore. + /// + /// It does not delete all the dependent items, this includes tasks and media. Future deleteEvent(String userId, String eventId) async { try { final documentReference = @@ -176,6 +186,11 @@ class FirestoreProvider { } } + /// Updates and event with the provided data. + /// + /// At least one of the following has to be provided (otherwise this + /// operation has no effect): [name], [pendingTasks], [meida], [tasks], + /// [highPriority], [mediumPriority] or [lowPriority]. Future updateEvent( String userId, String eventId, { @@ -198,6 +213,11 @@ class FirestoreProvider { }; newData.removeWhere((_, value) => value == null); + // No need to call firestore if there's no new data to update. + if (newData.isEmpty) { + return; + } + try { final documentReference = firestore.document('users/$userId/Events/$eventId');