In a page, I have two containers. The first container is supposed to display a listview with data. the data are coming from a query (see code below). I am filtering on two fields. One field contains the UID of the parent project, the other field is containing the status of the record.
//the code below is not working properly. I mean it does not display any record. I have checked the documents in Firebase, the UID and the fields. All the info was correct, but I do not understand why no record are displayed. Many thanks for your help.
Container(
//height: 200.0,
//width: MediaQuery.of(context).size.width,
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser.uid)
.collection('allTasks')
.where('task_Status', isNotEqualTo: 'Reference')
.where('parent_project_id', isEqualTo: prgID)
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshotTask) {
if (!snapshotTask.hasData) {
return Center(
child: Container(
height: 80.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('No task in this project'),
],
)),
);
}
return Expanded (
child: ListView(
children: snapshotTask.data.docs.map((document){
return Card(
child: SwipeActionCell(
key: ObjectKey(document['task_Name']),
trailingActions: <SwipeAction>[
SwipeAction(
title: "delete",
onTap: (CompletionHandler handler) {
CollectionReference users = FirebaseFirestore
.instance
.collection('Users')
.doc(
FirebaseAuth.instance.currentUser.uid)
.collection('allTasks');
users
.doc(document.id)
.delete()
.then((value) => print ('task deleted'))
.catchError((error)=> print("Failed to detele Task: $error"));
},
color: Colors.red),
],
child: ListTile(
leading:Icon(Icons.check_box_outline_blank),
title: Text(document['task_Name']),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: FlagWidgetTask(),
tooltip: 'Mark task as urgent',
onPressed: () {
}
),
IconButton(
icon: StarWidgetProject(),
tooltip: 'Mark task as important',
onPressed: () {
},
),
],
),
onTap: () {
},
),
),
) ;
}).toList(),
),
);
}),
),``
//the code below is working fine and display the records.
Container(
//height: 200.0,
//width: MediaQuery.of(context).size.width,
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser.uid)
.collection('allTasks')
.where('parent_project_id', isEqualTo: prgID)
.where('task_Status', isEqualTo: 'Reference')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshotReference) {
if (!snapshotReference.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return Expanded (
child: ListView(
children: snapshotReference.data.docs.map((document){
return Card(
child: ListTile(
leading:Icon(Icons.check_box_outline_blank),
title: Text(document['task_Name']),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: StarWidgetProject(),
tooltip: 'Mark task as important',
onPressed: () {
},
),
],
),
onTap: () {
},
),
) ;
}).toList(),
),
);
}),
),