Filter constructor

Filter(
  1. Object field, {
  2. Object? isEqualTo,
  3. Object? isNotEqualTo,
  4. Object? isLessThan,
  5. Object? isLessThanOrEqualTo,
  6. Object? isGreaterThan,
  7. Object? isGreaterThanOrEqualTo,
  8. Object? arrayContains,
  9. Iterable<Object?>? arrayContainsAny,
  10. Iterable<Object?>? whereIn,
  11. Iterable<Object?>? whereNotIn,
  12. bool? isNull,
})

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;
}