Filter<T extends Object> class sealed

Type-safe filter for querying data.

Provides comprehensive filtering with compile-time type safety. Supports comparison, list, existence, evaluation, path, and logical operations.

class User {
  final String name;
  final int age;
  final List<String> tags;
  User(this.name, this.age, this.tags);
}

extension type const UserField._(FilterField<User> field)
    implements FilterField<User> {
  const UserField(String name, Object? Function(User) getter)
      : this._(FilterField(name, getter));

  static const name = UserField('name', (u) => u.name);
  static const age = UserField('age', (u) => u.age);
  static const tags = UserField('tags', (u) => u.tags);
}

// Create complex filters
final filter = Filter.and([
  Filter.equal(UserField.name, 'John'),
  Filter.greater(UserField.age, 18),
  Filter.contains(UserField.tags, 'admin'),
]);

// Use for matching
final user = User('John', 25, ['admin']);
print(filter.matches(user)); // true

// Convert to JSON for API
final json = filter.toJson();

Constructors

Filter.and(Iterable<Filter<T>> filters)
Logical AND filter matching when all filters match.
const
factory
Filter.autoComplete(FilterField<T> field, String query)
Autocomplete filter matching field words starting with query.
const
factory
Filter.contains(FilterField<T> field, Object? value)
Containment filter matching field containing value.
const
factory
Filter.equal(FilterField<T> field, Object? value)
Equality filter matching field equal to value.
const
factory
Filter.exists(FilterField<T> field, {required bool exists})
Existence filter matching field presence when exists is true.
const
factory
Filter.greater(FilterField<T> field, Object? value)
Greater-than filter matching field greater than value.
const
factory
Filter.greaterOrEqual(FilterField<T> field, Object? value)
Greater-than-or-equal filter matching field >= value.
const
factory
Filter.in_(FilterField<T> field, Iterable<Object?> values)
Membership filter matching field value in values.
const
factory
Filter.less(FilterField<T> field, Object? value)
Less-than filter matching field less than value.
const
factory
Filter.lessOrEqual(FilterField<T> field, Object? value)
Less-than-or-equal filter matching field <= value.
const
factory
Filter.or(Iterable<Filter<T>> filters)
Logical OR filter matching when any filters match.
const
factory
Filter.pathExists(FilterField<T> field, String path)
Nested JSON path existence filter for field at path.
const
factory
Filter.query(FilterField<T> field, String query)
Full-text search filter matching field containing query.
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

matches(T other) bool
Whether this filter matches the given other instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, Object?>
Converts this filter to JSON format for API queries.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited