mergeComponentConfig static method
dynamic
mergeComponentConfig(
- Map<
LayoutPosition, ComponentConfig> defaultComponentConfig, - Map<
LayoutPosition, ComponentConfig> userComponentConfig
Implementation
static mergeComponentConfig(
Map<LayoutPosition, ComponentConfig> defaultComponentConfig,
Map<LayoutPosition, ComponentConfig> userComponentConfig,
) {
final Map<LayoutPosition, ComponentConfig> mergedComponents = {
...defaultComponentConfig,
};
userComponentConfig.forEach((position, config) {
// 如果默认配置中存在该位置的配置,使用 copyWith 合并;否则直接添加
if (mergedComponents.containsKey(position)) {
// 保留 builder,因为 builder 无法从 JSON 序列化
final existingBuilder = mergedComponents[position]?.builder;
mergedComponents[position] = mergedComponents[position]!.copyWith(
type: config.type,
isFloating: config.isFloating,
hasAnimation: config.hasAnimation,
isCollapsible: config.isCollapsible,
initiallyExpanded: config.initiallyExpanded,
animationDuration: config.animationDuration,
animationType: config.animationType,
width: config.width,
height: config.height,
margin: config.margin,
padding: config.padding,
customProps: config.customProps,
backgroundColor: config.backgroundColor,
showToggleButton: config.showToggleButton,
isShow: config.isShow,
builder: config.builder ?? existingBuilder,
);
} else {
mergedComponents[position] = config;
}
});
return mergedComponents;
}