Filter constructor
Filter(})
A Filter represents a restriction on one or more field values and can be used to refine the results of a Query.
Only one operator can be specified at a time.
Implementation
Filter(
/// The field or [FieldPath] to filter on.
Object field, {
/// Creates a new filter for checking that the given field is equal to the given value.
Object? isEqualTo,
/// Creates a new filter for checking that the given field is not equal to the given value.
Object? isNotEqualTo,
/// Creates a new filter for checking that the given field is less than the given value.
Object? isLessThan,
/// Creates a new filter for checking that the given field is less than or equal to the given value.
Object? isLessThanOrEqualTo,
/// Creates a new filter for checking that the given field is greater than the given value.
Object? isGreaterThan,
/// Creates a new filter for checking that the given field is greater than or equal to the given value.
Object? isGreaterThanOrEqualTo,
/// Creates a new filter for checking that the given array field contains the given value.
Object? arrayContains,
/// Creates a new filter for checking that the given array field contains any of the given values.
Iterable<Object?>? arrayContainsAny,
/// Creates a new filter for checking that the given field equals any of the given values.
Iterable<Object?>? whereIn,
/// Creates a new filter for checking that the given field does not equal any of the given values.
Iterable<Object?>? whereNotIn,
/// Creates a new filter for checking that the given field is null.
bool? isNull,
}) : assert(
() {
final operators = [
isEqualTo,
isNotEqualTo,
isLessThan,
isLessThanOrEqualTo,
isGreaterThan,
isGreaterThanOrEqualTo,
arrayContains,
arrayContainsAny,
whereIn,
whereNotIn,
isNull,
];
final operatorsUsed = operators.where((e) => e != null).length;
return operatorsUsed == 1;
}(),
'Exactly one operator must be specified',
),
assert(
field is String || field is FieldPath || field is FieldPathType,
) {
final _field = (field is String ? FieldPath.fromString(field) : field);
_filterQuery = _FilterQuery(
_field,
_getOperator(
isEqualTo,
isNotEqualTo,
isLessThan,
isLessThanOrEqualTo,
isGreaterThan,
isGreaterThanOrEqualTo,
arrayContains,
arrayContainsAny,
whereIn,
whereNotIn,
isNull,
),
_CodecUtility.valueEncode(
_getValue(
isEqualTo,
isNotEqualTo,
isLessThan,
isLessThanOrEqualTo,
isGreaterThan,
isGreaterThanOrEqualTo,
arrayContains,
arrayContainsAny,
whereIn,
whereNotIn,
isNull,
),
),
);
_filterOperator = null;
}