fromDynamic static method

JsonRichTextBuilder? fromDynamic(
  1. dynamic map, {
  2. JsonWidgetRegistry? registry,
})

Builds the builder from a Map-like dynamic structure. This expects the JSON format to be of the following structure:

{
  "locale": "<Locale>",
  "maxLines": "<int>",
  "overflow": "<TextOverflow>",
  "selectionColor": "<Color>",
  "selectionRegistrar": "<SelectionRegistrar>",
  "semanticsLabel": "<String>",
  "softWrap": "<bool>",
  "strutStyle": "<StrutStyle>",
  "style": "<TextStyle>",
  "text": "<TextSpan>",
  "textAlign": "<TextAlign>",
  "textDirection": "<TextDirection>",
  "textHeightBehavior": "<TextHeightBehavior>",
  "textScaleFactor": "<double>",
  "textWidthBasis": "<TextWidthBasis>"
}

See also:

  • ThemeDecoder.decodeColor
  • ThemeDecoder.decodeLocale
  • ThemeDecoder.decodeTextOverflow
  • ThemeDecoder.decodeStrutStyle
  • ThemeDecoder.decodeTextAlign
  • ThemeDecoder.decodeTextDirection
  • ThemeDecoder.decodeTextHeightBehavior
  • ThemeDecoder.decodeTextSpan
  • ThemeDecoder.decodeTextStyle
  • ThemeDecoder.decodeTextWidthBasis

Implementation

static JsonRichTextBuilder? fromDynamic(
  dynamic map, {
  JsonWidgetRegistry? registry,
}) {
  JsonRichTextBuilder? result;
  if (map != null) {
    result = JsonRichTextBuilder(
      locale: ThemeDecoder.decodeLocale(
        map['local'],
        validate: false,
      ),
      maxLines: JsonClass.maybeParseInt(map['maxLines']),
      overflow: ThemeDecoder.decodeTextOverflow(
            map['overflow'],
            validate: false,
          ) ??
          TextOverflow.clip,
      selectionColor: ThemeDecoder.decodeColor(
        map['selectionColor'],
        validate: false,
      ),
      selectionRegistrar: map['selectionRegistrar'],
      semanticsLabel: map['semanticsLabel'],
      softWrap: JsonClass.parseBool(
        map['softWrap'],
        whenNull: true,
      ),
      strutStyle: ThemeDecoder.decodeStrutStyle(
        map['strutStyle'],
        validate: false,
      ),
      text: ThemeDecoder.decodeTextSpan(
        map['text'],
        validate: false,
      )!,
      textAlign: ThemeDecoder.decodeTextAlign(
            map['textAlign'],
            validate: false,
          ) ??
          TextAlign.start,
      textDirection: ThemeDecoder.decodeTextDirection(
        map['textDirection'],
        validate: false,
      ),
      textHeightBehavior: ThemeDecoder.decodeTextHeightBehavior(
        map['textHeightBehavior'],
        validate: false,
      ),
      textScaleFactor:
          JsonClass.maybeParseDouble(map['textScaleFactor']) ?? 1.0,
      textWidthBasis: ThemeDecoder.decodeTextWidthBasis(
            map['textWidthBasis'],
            validate: false,
          ) ??
          TextWidthBasis.parent,
    );
  }

  return result;
}