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 src = map['src'];
  String? semanticLabel =
      map.containsKey('semanticLabel') ? map['semanticLabel'] : null;
  bool excludeFromSemantics = map.containsKey('excludeFromSemantics')
      ? map['excludeFromSemantics']
      : false;
  double scale = map.containsKey("scale") ? map['scale']?.toDouble() : 1.0;
  double? width = map.containsKey('width') ? map['width']?.toDouble() : null;
  double? height =
      map.containsKey('height') ? map['height']?.toDouble() : null;
  Color? color = map.containsKey('color') ? parseHexColor(map['color']) : null;
  BlendMode? colorBlendMode =
      map.containsKey('colorBlendMode') ? parseBlendMode(map['colorBlendMode']) : null;
  BoxFit? fit =
      map.containsKey('fit') ? parseBoxFit(map['fit']) : null;
  Alignment alignment = map.containsKey('alignment')
      ? parseAlignment(map['alignment'])!
      : Alignment.center;
  ImageRepeat repeat = map.containsKey('repeat')
      ? parseImageRepeat(map['repeat'])!
      : ImageRepeat.noRepeat;
  Rect? centerSlice =
      map.containsKey('centerSlice') ? parseRect(map['centerSlice']) : null;
  bool matchTextDirection = map.containsKey('matchTextDirection')
      ? map['matchTextDirection']
      : false;
  bool gaplessPlayback =
      map.containsKey('gaplessPlayback') ? map['gaplessPlayback'] : false;
  FilterQuality filterQuality = map.containsKey('filterQuality')
      ? parseFilterQuality(map['filterQuality'])!
      : FilterQuality.low;

  String? clickEvent =
      map.containsKey("click_event") ? map['click_event'] : "";

  var widget = Image.network(
    src,
    semanticLabel: semanticLabel,
    excludeFromSemantics: excludeFromSemantics,
    scale: scale,
    width: width,
    height: height,
    color: color,
    colorBlendMode: colorBlendMode,
    fit: fit,
    alignment: alignment,
    repeat: repeat,
    centerSlice: centerSlice,
    matchTextDirection: matchTextDirection,
    gaplessPlayback: gaplessPlayback,
    filterQuality: filterQuality,
  );

  if (listener != null && (clickEvent != null && clickEvent.isNotEmpty)) {
    return GestureDetector(
      onTap: () {
        listener.onClicked(clickEvent);
      },
      child: widget,
    );
  }
  return widget;
}