fromJson static method

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

Implementation

static InlineCountdownConfig? fromJson(Map<String, dynamic> json) {
  final slotKey = optString(json, 'slotKey').trim();
  final title = optString(json, 'title');
  final subtitle = optString(json, 'subtitle');
  final endTime = optString(json, 'endTime');
  final expiredTitle = _contentOrDefault(
    json,
    'expiredTitle',
    _defaultExpiredTitle,
  );
  final expiredSubtitle = _contentOrDefault(
    json,
    'expiredSubtitle',
    _defaultExpiredSubtitle,
  );
  final expiredBodyText = _contentOrDefault(
    json,
    'expiredBodyText',
    _defaultExpiredBodyText,
  );
  final expiredCtaText = _contentOrDefault(
    json,
    'expiredCtaText',
    _defaultExpiredCtaText,
  );

  if ([
    slotKey,
    title,
    subtitle,
    endTime,
    expiredTitle,
    expiredSubtitle,
    expiredBodyText,
    expiredCtaText,
  ].any((value) => value.trim().isEmpty)) {
    return null;
  }

  const actionParser = EngageActionParser();
  return InlineCountdownConfig(
    slotKey: slotKey,
    margin: CountdownCardMargin.fromJson(optMap(json, 'margin')),
    padding: CountdownCardPadding.fromJson(optMap(json, 'padding')),
    activeContent: CountdownHeaderContent(
      title: title,
      subtitle: subtitle,
      imageUrl: _optionalString(json, 'imageUrl'),
      imagePlaceholder: ImagePlaceholder.fromJson(
        optMap(json, 'imagePlaceholder'),
      ),
    ),
    deadline: CountdownDeadline(endTime),
    expiredContent: CountdownExpiredContent(
      header: CountdownHeaderContent(
        title: expiredTitle,
        subtitle: expiredSubtitle,
        imageUrl: _optionalString(json, 'expiredImageUrl'),
        imagePlaceholder: ImagePlaceholder.fromJson(
          optMap(json, 'expiredImagePlaceholder'),
        ),
      ),
      bodyImageUrl: _optionalString(json, 'expiredBodyImageUrl'),
      bodyImagePlaceholder: ImagePlaceholder.fromJson(
        optMap(json, 'expiredBodyImagePlaceholder'),
      ),
      bodyText: expiredBodyText,
      ctaText: expiredCtaText,
    ),
    onClick: actionParser.parse(optMap(json, 'onClick')),
    expiredOnClick: actionParser.parse(optMap(json, 'expiredOnClick')),
  );
}