AuthyoTheme.fromCustomization constructor
Builds a partial theme from the appCustomizationModel JSON returned by
the Authyo backend. Only keys present (and parseable) are set, so the
result is meant to be merged over defaults.
Implementation
factory AuthyoTheme.fromCustomization(Map<String, dynamic>? json) {
if (json == null) return const AuthyoTheme();
bool? flag(String k) => json[k] is bool ? json[k] as bool : null;
String? str(String k) {
final v = json[k];
if (v == null) return null;
final s = v.toString().trim();
return s.isEmpty ? null : s;
}
int? timer;
final rawTimer = json['resendButtonTimer'];
if (rawTimer is num) {
timer = rawTimer.toInt();
} else if (rawTimer != null) {
timer = int.tryParse(rawTimer.toString());
}
return AuthyoTheme(
primary: parseColor(json['buttonColor']),
background: parseColor(json['bodyBackground']),
surface: parseColor(json['bodyBackground']),
inputBackground: parseColor(json['inputBackground']),
inputBorder: parseColor(json['inputBorder']),
inputText: parseColor(json['inputText']),
buttonColor: parseColor(json['buttonColor']),
buttonTextColor: parseColor(json['buttonTextColor']),
buttonBorderColor: parseColor(json['buttonBorderColor']),
socialButtonColor: parseColor(json['smButtonColor']),
socialButtonTextColor: parseColor(json['smButtonText']),
socialButtonBorderColor: parseColor(json['smButtonBorder']),
headerText: str('headerText'),
headerTextColor: parseColor(json['headerTextColor']),
showHeader: flag('isHeader'),
bodyText: str('bodyText'),
bodyTextColor: parseColor(json['bodyTextColor']),
showBody: flag('isBody'),
showLogo: flag('isLogo'),
logoUrl: str('logoUrl'),
hideBranding: flag('hideBranding'),
resendTimerSeconds: timer,
buttonShape: json['buttonStyle'] == null
? null
: AuthyoButtonShape.fromValue(json['buttonStyle']),
mainLayout: json['mainLayout'] == null
? null
: AuthyoMainLayout.fromValue(json['mainLayout']),
socialLayout: json['socialMediaLayout'] == null
? null
: AuthyoSocialLayout.fromValue(json['socialMediaLayout']),
privacyLink: str('privacyLink'),
termsLink: str('termsLink'),
glassOpacity: json['glassOpacity'] is num
? ((json['glassOpacity'] as num).toDouble().clamp(20, 100) / 100)
: null,
inputShape:
(json['inputStyle'] is num &&
(json['inputStyle'] as num) > 0 &&
(json['inputStyle'] as num) < 4)
? AuthyoButtonShape.fromValue(json['inputStyle'])
: null,
inputUnderline: json['inputStyle'] is num
? (json['inputStyle'] as num) == 4
: null,
socialButtonShape:
(json['smButtonStyle'] is num &&
(json['smButtonStyle'] as num) > 0 &&
(json['smButtonStyle'] as num) < 4)
? AuthyoButtonShape.fromValue(json['smButtonStyle'])
: null,
socialButtonsFullWidth: json['smButtonSize'] is num
? (json['smButtonSize'] as num) == 2
: null,
otpHidden: flag('isOtpHide'),
rememberMe: flag('isRememberMe'),
rememberMeDays: json['rememberMeDays'] is num
? (json['rememberMeDays'] as num).toInt()
: null,
);
}