added not exists filter

This commit is contained in:
Deven Joshi
2021-09-27 17:46:57 +05:30
parent 771ba10999
commit a931682b4c
2 changed files with 12 additions and 5 deletions
@@ -40,9 +40,12 @@ enum FilterOperator {
/// Matches values with the specified prefix.
autoComplete,
/// Matches values that exist/don't exist based on the specified boolean value.
/// Matches values that exist.
exists,
/// Matches values that don't exist.
notExists,
/// Matches all the values specified in an array.
and,
@@ -163,9 +166,13 @@ class Filter extends Equatable {
factory Filter.autoComplete(String key, String text) =>
Filter._(operator: FilterOperator.autoComplete, key: key, value: text);
/// Matches values that exist/don't exist based on the specified boolean value.
factory Filter.exists(String key, {bool exists = true}) =>
Filter._(operator: FilterOperator.exists, key: key, value: exists);
/// Matches values that exist.
factory Filter.exists(String key) =>
Filter._(operator: FilterOperator.exists, key: key, value: true);
/// Matches values that don't exist.
factory Filter.notExists(String key) =>
Filter._(operator: FilterOperator.exists, key: key, value: false);
/// Matches any list that contains the specified values
factory Filter.contains(String key, Object value) =>
@@ -114,7 +114,7 @@ void main() {
test('notExists', () {
const key = 'testKey';
final filter = Filter.exists(key, exists: false);
final filter = Filter.notExists(key);
expect(filter.key, key);
expect(filter.value, isFalse);
expect(filter.operator, FilterOperator.exists.rawValue);