parse method

  1. @override
Widget parse(
  1. Map<String, dynamic> map,
  2. BuildContext buildContext,
  3. ClickListener? listener
)
override

parse the json map into a flutter widget.

Implementation

@override
Widget parse(Map<String, dynamic> map, BuildContext buildContext,
    ClickListener? listener) {
  String? data = (map['data'] as String?)?.tr();
  String? textAlignString = map['textAlign'];
  String? overflow = map['overflow'];
  int? maxLines = map['maxLines'];
  String? semanticsLabel = map['semanticsLabel'];
  bool? softWrap = map['softWrap'];
  String? textDirectionString = map['textDirection'];
  double? textScaleFactor = map['textScaleFactor']?.toDouble();
  var textSpan;
  var textSpanParser = TextSpanParser();
  if (map.containsKey("textSpan")) {
    textSpan = textSpanParser.parse(map['textSpan'], listener);
  }

  if (textSpan == null) {
    return Text(
      data ?? '',
      textAlign: parseTextAlign(textAlignString),
      overflow: parseTextOverflow(overflow),
      maxLines: maxLines,
      semanticsLabel: semanticsLabel,
      softWrap: softWrap,
      textDirection: parseTextDirection(textDirectionString),
      style: map.containsKey('style') ? parseTextStyle(map['style']) : null,
      textScaleFactor: textScaleFactor,
    );
  } else {
    return Text.rich(
      textSpan,
      textAlign: parseTextAlign(textAlignString),
      overflow: parseTextOverflow(overflow),
      maxLines: maxLines,
      semanticsLabel: semanticsLabel,
      softWrap: softWrap,
      textDirection: parseTextDirection(textDirectionString),
      style: map.containsKey('style') ? parseTextStyle(map['style']) : null,
      textScaleFactor: textScaleFactor,
    );
  }
}