Filter.fromJson constructor

Filter.fromJson(
  1. Map<String, dynamic> json
)

Creates a Filter instance from a JSON map.

Handles two formats:

  1. Simple equality: {"fieldName": value}
  2. Operator-based: {"fieldName": {"$operator": value}}

Example:

// Simple equality
Filter.fromJson({"name": "John"}); // Creates equality filter

// Operator-based
Filter.fromJson({
  "age": {">=": 18}
}); // Creates "greater than" filter

Implementation

factory Filter.fromJson(Map<String, dynamic> json) {
  final entry = json.entries.first;
  if (entry.value is Map) {
    final opEntry = (entry.value as Map).entries.first;
    return Filter(entry.key, opEntry.value, opEntry.key.replaceAll(r'$', ''));
  } else {
    return Filter(entry.key, entry.value, '==');
  }
}