slotBuilders property
插槽构建器映射,允许自定义各个插槽的构建方式
Slot builder map, allowing customization of how each slot is built
Key 为 SlotType,支持内置插槽和自定义插槽:
- 内置插槽:使用预定义常量(如
SlotType.topBar、SlotType.bottomBar) - 自定义插槽:通过
SlotType('name', defaultOrder: N)创建,defaultOrder决定插槽在 Stack 中的层级位置
Key is SlotType, supporting both built-in and custom slots:
- Built-in: Use predefined constants (e.g.
SlotType.topBar,SlotType.bottomBar) - Custom: Create via
SlotType('name', defaultOrder: N), wheredefaultOrderdetermines the slot's z-level in the Stack
Value 为 SlotWidgetBuilder 构建器:
Widget Function(BuildContext context)
对于内置插槽,支持三种用法:
- 不提供 key:使用默认实现
- key 对应非 null 构建器:使用自定义构建器完全替换该插槽
- key 对应 null:禁用该插槽(返回 SizedBox.shrink)
示例 / Example:
// 定义自定义插槽,order=35 自动落在 coverImage(30) 和 playControl(40) 之间
const watermark = SlotType('watermark', defaultOrder: 35);
slotBuilders: {
// 替换内置插槽
SlotType.topBar: (ctx) => MyCustomTopBar(),
// 注册自定义插槽(按 defaultOrder 自动排序)
watermark: (ctx) => WatermarkWidget(),
}
Implementation
final Map<SlotType, SlotWidgetBuilder?> slotBuilders;