If you've ever struggled with complex filters in Firebase, youβll love Filter.and() and Filter.or(). These let you easily combine multiple conditions without chaining .where() calls endlessly.
π₯ AND queries:
Need all conditions to be true? Just wrap them in Filter.and().
query.where(Filter.and(
Filter("status", isEqualTo: "active"),
Filter("role", isEqualTo: "admin"),
));
β‘ OR queries:
Need at least one condition to match? Use Filter.or().
query.where(Filter.or(
Filter("age", isGreaterThan: 18),
Filter("verified", isEqualTo: true),
));
π‘ Combining AND & OR:
You can nest Filter.and() and Filter.or() for advanced queries without writing inefficient workarounds.
query.where(Filter.and(
Filter("country", isEqualTo: "USA"),
Filter.or(
Filter("premiumUser", isEqualTo: true),
Filter("subscription", isGreaterThanOrEqualTo: 1),
),
));
β¨ Why use this?
β
Cleaner, more readable queries
β
No more chaining .where() for complex filters
β
Firestore handles everything under the hood efficiently
This makes querying Firestore data in Flutter much more flexible! π
If you're still using old .where() chains, it's time to upgrade.
Who's already using Filter.and() & Filter.or()?
Let me know your experience! π₯
Top comments (0)