fromJson static method

RichTextObject? fromJson(
  1. dynamic value
)

Returns a new RichTextObject instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static RichTextObject? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'type'), 'Required key "RichTextObject[type]" is missing from JSON.');
      assert(json[r'type'] != null, 'Required key "RichTextObject[type]" has a null value in JSON.');
      return true;
    }());

    return RichTextObject(
      type: RichTextObjectTypeEnum.fromJson(json[r'type'])!,
      text: mapValueOfType<String>(json, r'text'),
      annotations: TextAnnotations.fromJson(json[r'annotations']),
      href: mapValueOfType<String>(json, r'href'),
    );
  }
  return null;
}