DEV Community

Cover image for Firestore just made querying data in Flutter way more powerful! ๐Ÿš€
Usama Sarwar
Usama Sarwar

Posted on

Firestore just made querying data in Flutter way more powerful! ๐Ÿš€

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"),
));
Enter fullscreen mode Exit fullscreen mode

โšก OR queries:

Need at least one condition to match? Use Filter.or().

query.where(Filter.or(
  Filter("age", isGreaterThan: 18),
  Filter("verified", isEqualTo: true),
));
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’ก 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),
  ),
));
Enter fullscreen mode Exit fullscreen mode

โœจ 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! ๐Ÿ”ฅ

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs