toJsonClean method
Returns the result of toJson, removing all null valued entries.
class Item extends Serialisable {
const(this.name, this.count);
final String name;
final int? count;
}
final Item x = Item('apple', null);
print(x.toJson()); // { 'name': 'apple', 'count': null }
print(x.toJsonClean()); // { 'name': 'apple' }
Implementation
Map<String, dynamic> toJsonClean() {
return toJson()..removeWhere((_, value) => value == null);
}