Mr Special
Mr Special

Reputation: 1676

Query multi condition firebase realtime database in Flutter

I'm using flutter to query the database. I have a real-time database as below: enter image description here

I want to select a record by condition: email='[email protected]' and password='111111'

I read the solution following link Query based on multiple where clauses in Firebase But it does not compatible with flutter. My code looks like:

var snapshot = await _firestore
      .reference()
      .child(USERS_TBL)
      .orderByChild('email')
      .equalTo(email)
      .once()
      .then((DataSnapshot snapshot) {
        print(snapshot.value);
  });

output:

{-LeXpDcLqkwS0c1lgP7O: {user_role: USER, password: 111111, gender: 1, last_name: abcee, first_name: abcd, email: [email protected]}}

Of course, I can parse value to get password value, but I think there is another solution which is better. How can I do in flutter? Thanks a lot!!!

Upvotes: 1

Views: 3163

Answers (1)

Omatt
Omatt

Reputation: 10453

I suggest using Firestore if you're looking for flexible queries. With Firestore, you can run a query for your use case like this:

FirebaseFirestore.instance
    .collection(USERS_TBL)
    .where('email', isEqualTo: email).snapshots()

This returns a QuerySnapshot of all Documents in the collection with the same email.

Upvotes: 1

Related Questions