putJSONableIfNotEmpty method

void putJSONableIfNotEmpty(
  1. String name,
  2. JSONable? jsonable
)

Maps name to jsonable after converting it to a Map, clobbering any existing name/value mapping with the same name. If the Map argument is empty, any existing mapping for name is removed.

Implementation

void putJSONableIfNotEmpty(String name, JSONable? jsonable) {
  Map<String, dynamic>? json = jsonable?.toJson();
  if (json == null || json.isEmpty) {
    this?.remove(name);
    return;
  }
  put(name, json);
}