encode<T> static method

void encode<T>(
  1. Map<String, dynamic> json,
  2. String key,
  3. T? value, [
  4. Map<String, dynamic> toJson(
    1. T
    )?,
])

Encodes an optional value to a JSON map if not null.

toJson - Optional function to encode objects. If not provided, value is used directly.

Implementation

static void encode<T>(
  Map<String, dynamic> json,
  String key,
  T? value, [
  Map<String, dynamic> Function(T)? toJson,
]) {
  if (value != null) {
    json[key] = toJson != null ? toJson(value) : value;
  }
}