fromJson static method

GuideAction fromJson(
  1. Map<String, dynamic> json
)

Implementation

static GuideAction fromJson(Map<String, dynamic> json) {
  final legacyType = _normalizedLegacyActionType(
    optString(json, 'type', 'dismiss'),
  );
  final url = _optStringOrNull(json, 'url');
  final onClick = optMap(json, 'onClick');
  // The dashboard may retain an empty action-flow placeholder. It must not
  // erase the legacy button action that still carries the behavior.
  final hasCanonicalActions =
      onClick != null && (optList(onClick, 'steps')?.isNotEmpty ?? false);
  final actions = hasCanonicalActions
      ? const EngageActionParser().parse(onClick)
      : _legacyEngageActions(legacyType, url);
  return GuideAction(
    label: optString(json, 'label'),
    style: _styleFrom(optString(json, 'style', 'primary')),
    actions: actions,
    analyticsType: actions.isEmpty ? legacyType : actions.first.analyticsType,
    backgroundColor: _color(json, 'backgroundColor'),
    textColor: _color(json, 'textColor'),
    fontSize: _positive(json['fontSize'], 13),
    fontWeight: _weight(json['fontWeight'], fallback: FontWeight.w600),
    cornerRadius: _nonNegative(json['cornerRadius'], 8),
    padding: _edges(
      json['padding'],
      const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
    ),
    margin: json.containsKey('margin')
        ? _edges(json['margin'], EdgeInsets.zero)
        : null,
  );
}