MetadataValue.fromJson constructor

MetadataValue.fromJson(
  1. dynamic json
)

Creates the value from its JSON representation

Implementation

factory MetadataValue.fromJson(dynamic json) {
  if (json is bool) return MetadataBool(json);
  if (json is num) return MetadataNumber(json);
  if (json is String) return MetadataString(json);
  if (json is Map) {
    if (json.length == 1 && json['timestamp'] != null) {
      return MetadataDate(parseNum(json['timestamp']));
    }
    if (json.length == 2 && json['value'] != null && json['unit'] is String) {
      return MetadataQuantity(parseNum(json['value']), json['unit']);
    }
  }
  throw FormatException('Invalid metadata value: $json');
}