toJson method
Implementation
String toJson() {
final root = <String, Object?>{};
try {
root['bridgeVersion'] = gameBridgeVersion;
root['chanceId'] = chanceId;
root['campaignKey'] = campaignKey;
root['campaign'] = {
'id': campaignId,
'campaignKey': campaignKey,
'skinId': skinId,
'skinVersion': skinVersion,
};
root['values'] = _objectOr(valuesJson);
root['slots'] = _arrayOr(slotsJson ?? '[]');
root['surface'] = surface;
root['viewport'] = {
'width': viewportWidth,
'height': viewportHeight,
'safeArea': {
'top': safeArea.top,
'right': safeArea.right,
'bottom': safeArea.bottom,
'left': safeArea.left,
},
'keyboardInset': {'bottom': keyboardInsetBottom},
};
root['theme'] = {
'colorScheme': colorScheme,
if (fontFamily != null) 'fontFamily': fontFamily,
'fonts': _arrayOr(fontsJson),
};
root['device'] = _objectOr(deviceJson);
final raw = chanceStateJson;
if (raw != null) {
try {
final state = jsonDecode(raw);
if (state is Map) root['chanceState'] = state;
} catch (_) {}
}
} catch (_) {}
return jsonEncode({'type': 'init', 'payload': root});
}