fromJson static method

TextAnnotations? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static TextAnnotations? 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'bold'), 'Required key "TextAnnotations[bold]" is missing from JSON.');
      assert(json[r'bold'] != null, 'Required key "TextAnnotations[bold]" has a null value in JSON.');
      assert(json.containsKey(r'italic'), 'Required key "TextAnnotations[italic]" is missing from JSON.');
      assert(json[r'italic'] != null, 'Required key "TextAnnotations[italic]" has a null value in JSON.');
      assert(json.containsKey(r'strikethrough'), 'Required key "TextAnnotations[strikethrough]" is missing from JSON.');
      assert(json[r'strikethrough'] != null, 'Required key "TextAnnotations[strikethrough]" has a null value in JSON.');
      assert(json.containsKey(r'underline'), 'Required key "TextAnnotations[underline]" is missing from JSON.');
      assert(json[r'underline'] != null, 'Required key "TextAnnotations[underline]" has a null value in JSON.');
      assert(json.containsKey(r'code'), 'Required key "TextAnnotations[code]" is missing from JSON.');
      assert(json[r'code'] != null, 'Required key "TextAnnotations[code]" has a null value in JSON.');
      return true;
    }());

    return TextAnnotations(
      bold: mapValueOfType<bool>(json, r'bold')!,
      italic: mapValueOfType<bool>(json, r'italic')!,
      strikethrough: mapValueOfType<bool>(json, r'strikethrough')!,
      underline: mapValueOfType<bool>(json, r'underline')!,
      code: mapValueOfType<bool>(json, r'code')!,
      color: mapValueOfType<String>(json, r'color'),
    );
  }
  return null;
}