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< filters)T> > -
Logical AND filter matching when all
filtersmatch.constfactory -
Filter.autoComplete(FilterField<
T> field, String query) -
Autocomplete filter matching
fieldwords starting withquery.constfactory -
Filter.contains(FilterField<
T> field, Object? value) -
Containment filter matching
fieldcontainingvalue.constfactory -
Filter.equal(FilterField<
T> field, Object? value) -
Equality filter matching
fieldequal tovalue.constfactory -
Filter.exists(FilterField<
T> field, {required bool exists}) -
Existence filter matching
fieldpresence whenexistsis true.constfactory -
Filter.greater(FilterField<
T> field, Object? value) -
Greater-than filter matching
fieldgreater thanvalue.constfactory -
Filter.greaterOrEqual(FilterField<
T> field, Object? value) -
Greater-than-or-equal filter matching
field>=value.constfactory -
Filter.in_(FilterField<
T> field, Iterable<Object?> values) -
Membership filter matching
fieldvalue invalues.constfactory -
Filter.less(FilterField<
T> field, Object? value) -
Less-than filter matching
fieldless thanvalue.constfactory -
Filter.lessOrEqual(FilterField<
T> field, Object? value) -
Less-than-or-equal filter matching
field<=value.constfactory -
Filter.or(Iterable<
Filter< filters)T> > -
Logical OR filter matching when any
filtersmatch.constfactory -
Filter.pathExists(FilterField<
T> field, String path) -
Nested JSON path existence filter for
fieldatpath.constfactory -
Filter.query(FilterField<
T> field, String query) -
Full-text search filter matching
fieldcontainingquery.constfactory
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
otherinstance. -
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