Changed id to be optional on [EventModel], [TaskModel] and [UserModel]
This commit is contained in:
parent
a68b307eeb
commit
8498517b1e
4 changed files with 25 additions and 9 deletions
|
|
@ -12,7 +12,7 @@ class EventModel {
|
|||
final int lowPriority;
|
||||
|
||||
EventModel({
|
||||
@required this.id,
|
||||
this.id,
|
||||
@required this.name,
|
||||
@required this.pendigTasks,
|
||||
@required this.when,
|
||||
|
|
@ -23,7 +23,7 @@ class EventModel {
|
|||
@required this.lowPriority,
|
||||
});
|
||||
|
||||
EventModel.fromFirestore(Map<String, dynamic> firestoreMap, String id)
|
||||
EventModel.fromFirestore(Map<String, dynamic> firestoreMap, {String id})
|
||||
: id = id,
|
||||
name = firestoreMap["name"],
|
||||
pendigTasks = firestoreMap["pendingTasks"],
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class TaskModel {
|
|||
final String event;
|
||||
|
||||
TaskModel({
|
||||
@required this.id,
|
||||
this.id,
|
||||
@required this.text,
|
||||
@required this.priority,
|
||||
@required this.ownerUsername,
|
||||
|
|
@ -17,7 +17,7 @@ class TaskModel {
|
|||
@required this.event,
|
||||
});
|
||||
|
||||
TaskModel.fromFirestore(Map<String, dynamic> firestoreMap, String id)
|
||||
TaskModel.fromFirestore(Map<String, dynamic> firestoreMap, {String id})
|
||||
: id = id,
|
||||
text = firestoreMap["text"],
|
||||
priority = firestoreMap["priority"],
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class UserModel {
|
|||
assert(pendingLow != null);
|
||||
|
||||
///Returns a [UserModel] from a map.
|
||||
UserModel.fromFirestore(Map<String, dynamic> firestoreMap, String id)
|
||||
UserModel.fromFirestore(Map<String, dynamic> firestoreMap, {String id})
|
||||
: id = id,
|
||||
username = firestoreMap["username"],
|
||||
tasks = firestoreMap["tasks"].cast<int>(),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import '../models/user_model.dart';
|
|||
import '../models/task_model.dart';
|
||||
|
||||
/// A connection to the Cloud Firestore database
|
||||
///
|
||||
/// Implempents CRUD operations for users, tasks and events.
|
||||
class FirestoreProvider {
|
||||
final Firestore firestore = Firestore.instance;
|
||||
|
||||
|
|
@ -26,12 +28,16 @@ class FirestoreProvider {
|
|||
}
|
||||
final userSnapshot = snapshot.documents.first;
|
||||
return UserModel.fromFirestore(
|
||||
userSnapshot.data, userSnapshot.documentID);
|
||||
userSnapshot.data,
|
||||
id: userSnapshot.documentID,
|
||||
);
|
||||
},
|
||||
);
|
||||
return Observable(mappedStream);
|
||||
}
|
||||
|
||||
//-------------------------Task related operations----------------------------
|
||||
|
||||
/// Returns a stream of [List<Task>]
|
||||
///
|
||||
/// The [event] parameter is used to query tasks that only are part of a
|
||||
|
|
@ -50,7 +56,10 @@ class FirestoreProvider {
|
|||
(QuerySnapshot snapshot) {
|
||||
return snapshot.documents.map(
|
||||
(DocumentSnapshot document) {
|
||||
return TaskModel.fromFirestore(document.data, document.documentID);
|
||||
return TaskModel.fromFirestore(
|
||||
document.data,
|
||||
id: document.documentID,
|
||||
);
|
||||
},
|
||||
).toList();
|
||||
},
|
||||
|
|
@ -63,13 +72,18 @@ class FirestoreProvider {
|
|||
final mappedStream =
|
||||
firestore.collection('tasks').document(id).snapshots().map(
|
||||
(DocumentSnapshot snapshot) {
|
||||
return TaskModel.fromFirestore(snapshot.data, snapshot.documentID);
|
||||
return TaskModel.fromFirestore(
|
||||
snapshot.data,
|
||||
id: snapshot.documentID,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return Observable(mappedStream);
|
||||
}
|
||||
|
||||
//-----------------------Event related operations-----------------------------
|
||||
|
||||
// TODO: Change the Events collction name to 'events'
|
||||
Observable<List<EventModel>> getUserEvents(String userDocumentId) {
|
||||
final mappedStream = firestore
|
||||
|
|
@ -81,7 +95,9 @@ class FirestoreProvider {
|
|||
(QuerySnapshot snapshot) {
|
||||
return snapshot.documents.map((DocumentSnapshot documentSnapshot) {
|
||||
return EventModel.fromFirestore(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
documentSnapshot.data,
|
||||
id: documentSnapshot.documentID,
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue