CustomComponentConfig.fromJson constructor
CustomComponentConfig.fromJson(
- Map<
String, dynamic> json, { - required Widget builder(
- BuildContext context
从 JSON 创建 CustomComponentConfig 实例 注意:builder 无法从 JSON 反序列化,需要在创建后手动设置
Implementation
factory CustomComponentConfig.fromJson(
Map<String, dynamic> json, {
required Widget Function(BuildContext context) builder,
}) {
return CustomComponentConfig(
builder: builder,
top: json['top']?.toDouble(),
left: json['left']?.toDouble(),
bottom: json['bottom']?.toDouble(),
right: json['right']?.toDouble(),
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>?,
showToggleButton: json['showToggleButton'] ?? true,
isShow: json['isShow'] ?? true,
);
}