toJson method

Object? toJson(
  1. Object? callback(
    1. T? value
    )
)

Implementation

Object? toJson(Object? Function(T? value) callback) {
  final rootValue = callback(value);
  final entries = values.entries.map((e) {
    final mapped = callback(e.value);
    if (mapped == null) return null;
    return MapEntry(e.key, mapped);
  }).whereType<MapEntry<String, Object>>();
  final map = Map.fromEntries(entries);
  if (rootValue != null) map['en'] = rootValue;
  if (map.length <= 1) return rootValue;
  return map;
}