Filter.fromJson constructor
Creates a Filter instance from a JSON map.
Handles two formats:
- Simple equality:
{"fieldName": value}
- 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, '==');
}
}