LayoutConfig.fromJson constructor
从 JSON 创建 LayoutConfig 实例
Implementation
factory LayoutConfig.fromJson(Map<String, dynamic> json) {
final componentsMap = <LayoutPosition, ComponentConfig?>{};
if (json['components'] != null) {
final componentsJson = json['components'] as Map<String, dynamic>;
componentsJson.forEach((key, value) {
final position = LayoutPosition.values.firstWhere(
(e) => e.toString() == 'LayoutPosition.$key',
orElse: () => LayoutPosition.center,
);
componentsMap[position] =
value != null
? ComponentConfig.fromJson(value as Map<String, dynamic>)
: null;
});
}
return LayoutConfig(
mode: LayoutMode.values.firstWhere(
(e) => e.toString() == 'LayoutMode.${json['mode']}',
orElse: () => LayoutMode.portrait,
),
components: componentsMap,
backgroundColor:
json['backgroundColor'] != null
? Color(json['backgroundColor'])
: null,
showDebugBounds: json['showDebugBounds'] ?? false,
accordionMode: json['accordionMode'] ?? true,
enableFloatingAutoHide: json['enableFloatingAutoHide'] ?? true,
floatingAutoHideDelay:
json['floatingAutoHideDelay'] != null
? Duration(seconds: json['floatingAutoHideDelay'])
: const Duration(seconds: 5),
);
}