fromCampaignJson static method
Parses a guide from a campaign's JSON, mirroring RN's _parseTemplateConfig
(flat templateConfig with templateType tooltip/spotlight).
Implementation
static GuideConfig? fromCampaignJson(Map<String, dynamic> json) {
final tc = optMap(json, 'templateConfig');
if (tc == null) return null;
final type = optString(tc, 'templateType');
final rawSteps = optList(tc, 'steps') ?? const [];
final templateId = _optStringOrNull(tc, 'templateId');
final outsideTap = optString(tc, 'outsideTapBehavior', 'next');
if (type == 'tooltip') {
final steps = <TooltipStep>[];
for (final raw in rawSteps) {
if (raw is Map) {
final s = TooltipStep.fromJson(raw.cast<String, dynamic>());
if (s != null) steps.add(s);
}
}
if (steps.isEmpty) return null;
return TooltipGuideConfig(
steps: steps, templateId: templateId, outsideTapBehavior: outsideTap);
}
if (type == 'spotlight') {
final steps = <SpotlightStep>[];
for (final raw in rawSteps) {
if (raw is Map) {
final s = SpotlightStep.fromJson(raw.cast<String, dynamic>());
if (s != null) steps.add(s);
}
}
if (steps.isEmpty) return null;
return SpotlightGuideConfig(
steps: steps, templateId: templateId, outsideTapBehavior: outsideTap);
}
return null;
}