Home > Blockchain >  Flutter - FireBase compound query - does not display any result
Flutter - FireBase compound query - does not display any result

Time:11-03

I am trying to create compound query. I am always getting this 'No data available'. It is strange, because there are data which match my query. Please, can you help me to figure out what I am missing? Thank you


Future myQuery () async{

    final currentQuery = FirebaseFirestore.instance
        .collection('Users')
        .doc(FirebaseAuth.instance.currentUser!.uid)
        .collection('allTasks');

    Query nameQuery = currentQuery.where('status', isEqualTo: 'Inbox');
    Query nameValorQuery = nameQuery.where('important', isEqualTo: 'False');
    
    final snapshot = await nameValorQuery.firestore.collection('allTasks').get(); //('users/$userId').get();

    if (snapshot.docs.isNotEmpty) {
      print(snapshot.docs.first);
    } else {
      print (snapshot.docs.length);
      print('No data available.');
    }


CodePudding user response:

I fixed your code. this should work. Hope it helps.

  Future myQuery () async{
    final uid = FirebaseAuth.instance.currentUser!.uid;
    final path = 'Users/$uid/allTasks';

    final currentQuery = FirebaseFirestore.instance.collection(path);
    Query nameQuery = currentQuery.where('status', isEqualTo: 'Inbox');
    Query nameValorQuery = nameQuery.where('important', isEqualTo: 'False');
    
    final snapshot = await nameValorQuery.get();

    final data = snapshot.docs;
    if(data.isNotEmpty){
      for(var i =0; i < data.length; i  ){
        print(data[i].data());
      }
    }
    }

  • Related