ComponentConfig.fromJson constructor

ComponentConfig.fromJson(
  1. Map<String, dynamic> json
)

从 JSON 创建 ComponentConfig 实例

Implementation

factory ComponentConfig.fromJson(Map<String, dynamic> json) {
  return ComponentConfig(
    type:
        json['type'] != null
            ? ComponentType.values.firstWhere(
              (e) => e.toString() == 'ComponentType.${json['type']}',
              orElse: () => ComponentType.custom,
            )
            : null,
    isFloating: json['isFloating'] ?? false,
    hasAnimation: json['hasAnimation'] ?? false,
    isCollapsible: json['isCollapsible'] ?? false,
    initiallyExpanded: json['initiallyExpanded'] ?? true,
    animationDuration:
        json['animationDuration'] != null
            ? Duration(milliseconds: json['animationDuration'])
            : const Duration(milliseconds: 300),
    animationType:
        json['animationType'] != null
            ? AnimationType.values.firstWhere(
              (e) => e.toString() == 'AnimationType.${json['animationType']}',
              orElse: () => AnimationType.none,
            )
            : null,
    width: json['width']?.toDouble(),
    height: json['height']?.toDouble(),
    margin:
        json['margin'] != null
            ? EdgeInsets.fromLTRB(
              json['margin']['left']?.toDouble() ?? 0,
              json['margin']['top']?.toDouble() ?? 0,
              json['margin']['right']?.toDouble() ?? 0,
              json['margin']['bottom']?.toDouble() ?? 0,
            )
            : null,
    padding:
        json['padding'] != null
            ? EdgeInsets.fromLTRB(
              json['padding']['left']?.toDouble() ?? 0,
              json['padding']['top']?.toDouble() ?? 0,
              json['padding']['right']?.toDouble() ?? 0,
              json['padding']['bottom']?.toDouble() ?? 0,
            )
            : null,
    customProps: json['customProps'] as Map<String, dynamic>?,
    backgroundColor:
        json['backgroundColor'] != null
            ? Color(json['backgroundColor'])
            : null,
    showToggleButton: json['showToggleButton'] ?? false,
    isShow: json['isShow'] ?? true,
  );
}