0

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(),
                  ),
                );
              }),
        ),
Laurent Thomas
  • 232
  • 4
  • 24
  • Have you created index for the same? from run? – Ankit Gada Aug 30 '21 at 20:49
  • No. I have not created any index – Laurent Thomas Aug 30 '21 at 21:26
  • 2
    When you run this code in your run you will find some links, the complier tells us to create a index as it a complex query, so just click on it and you will be redirected to firebase Console to create a indexes, let this process be done. – Ankit Gada Aug 31 '21 at 02:17
  • Thank you. I have not been clear enough. The UID and the status are in the same document. So I do not understand how the creation of an index will help. It is not two different documents. – Laurent Thomas Aug 31 '21 at 06:26

0 Answers0