ComponentConfig.fromJson constructor
从 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'] as bool?,
isDraggable: json['isDraggable'] as bool?,
dragSnapToEdge: json['dragSnapToEdge'] as bool?,
hasAnimation: json['hasAnimation'] as bool?,
isCollapsible: json['isCollapsible'] as bool?,
initiallyExpanded: json['initiallyExpanded'] as bool?,
animationDuration:
json['animationDuration'] != null
? Duration(milliseconds: json['animationDuration'])
: null,
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(),
top: json['top']?.toDouble(),
left: json['left']?.toDouble(),
bottom: json['bottom']?.toDouble(),
right: json['right']?.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'] as bool?,
isShow: json['isShow'] as bool?,
);
}