Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
780 views
in Technique[技术] by (71.8m points)

firebase - how to configure multiple conditional queries for firestore in flutter application

I am able set two different queries for the firestore database on conditional analysis using ternary operator, but what if I have to use 5 different conditions for the same stream to build up the query? How can I do that?

                  stream: (query != "" && query != null)
                      ? FirebaseFirestore.instance
                       .collection('momos_nv')
                       .orderBy('itemName')
                       .startAt([query])
                       .endAt([query + 'uf8ff']).snapshots()
                      : FirebaseFirestore.instance.collection("momos_nv").snapshots()
question from:https://stackoverflow.com/questions/66057510/how-to-configure-multiple-conditional-queries-for-firestore-in-flutter-applicati

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can create a separate method with return type Stream.

final CollectionReference collection =
      FirebaseFirestore.instance.collection('employees');

  Stream<QuerySnapshot> getStream(String query) {
    /// Perform your 5 condition here 
    return collection.snapshots();
  }

stream: getStream(query),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...