fromJson static method
Parses a carousel templateConfig object. Returns null when the config
is missing a slotKey or has no valid items — mirroring Android, where
such campaigns are dropped rather than rendered empty.
Implementation
static InlineCarouselConfig? fromJson(Map<String, dynamic> json) {
final slotKey = optString(json, 'slotKey');
if (slotKey.isEmpty) return null;
final itemsArr = optList(json, 'items');
if (itemsArr == null) return null;
final items = <CarouselItem>[];
for (final raw in itemsArr) {
if (raw is! Map) continue;
final itemJson = raw.cast<String, dynamic>();
final imageUrl = optString(itemJson, 'imageUrl');
if (imageUrl.isEmpty) continue;
final deepLink = optString(itemJson, 'deepLink');
items.add(CarouselItem(
imageUrl: imageUrl,
deepLink: deepLink.isEmpty ? null : deepLink,
));
}
if (items.isEmpty) return null;
final widthValue = json['width'];
final width = widthValue is num && widthValue.toInt() > 0
? widthValue.toInt()
: null;
return InlineCarouselConfig(
slotKey: slotKey,
items: items,
height: optInt(json, 'height', 180),
width: width,
autoPlay: optBool(json, 'autoPlay', true),
autoPlayInterval: optInt(json, 'autoPlayInterval', 3000),
animationDuration: optInt(json, 'animationDuration', 700),
infiniteScroll: optBool(json, 'infiniteScroll', true),
viewportFraction: optDouble(json, 'viewportFraction', 0.88),
indicator: CarouselIndicatorConfig.fromJson(optMap(json, 'indicator')),
);
}