JsonObject constructor

JsonObject(
  1. Object? value
)

Instantiates with value, which must be a bool, a List, a Map, a num or a String. Otherwise, an ArgumentError is thrown.

Implementation

factory JsonObject(Object? value) {
  if (value is num) {
    return NumJsonObject(value);
  } else if (value is String) {
    return StringJsonObject(value);
  } else if (value is bool) {
    return BoolJsonObject(value);
  } else if (value is List<Object?>) {
    return ListJsonObject(value);
  } else if (value is Map<String, Object?>) {
    return MapJsonObject(value);
  } else if (value is Map) {
    // Allow wrong type map, check individual values.
    return MapJsonObject(value.cast());
  } else {
    throw ArgumentError.value(value, 'value',
        'Must be bool, List<Object?>, Map<String?, Object?>, num or String');
  }
}