SwitchButton constructor

SwitchButton({
  1. Key? key,
  2. required bool value,
  3. required ValueChanged<bool>? onChanged,
  4. required Color activeTrackColor,
  5. required Color inactiveTrackColor,
  6. ImageProvider<Object>? activeThumbImage,
  7. ImageErrorListener? onActiveThumbImageError,
  8. ImageProvider<Object>? inactiveThumbImage,
  9. ImageErrorListener? onInactiveThumbImageError,
  10. WidgetStateProperty<Color?>? thumbColor,
  11. WidgetStateProperty<Color?>? trackColor,
  12. WidgetStateProperty<double?>? trackOutlineWidth,
  13. WidgetStateProperty<Icon?>? thumbIcon,
  14. MaterialTapTargetSize? materialTapTargetSize,
  15. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  16. MouseCursor? mouseCursor,
  17. Color? focusColor,
  18. Color? hoverColor,
  19. WidgetStateProperty<Color?>? overlayColor,
  20. double? splashRadius,
  21. FocusNode? focusNode,
  22. ValueChanged<bool>? onFocusChange,
  23. bool autofocus = false,
  24. EdgeInsetsGeometry? padding,
})

创建一个自定义开关。

value 表示当前开关状态,onChanged 在状态切换时回传新值; activeTrackColorinactiveTrackColor 分别设置开启与关闭时的轨道颜色。

Implementation

SwitchButton({
  super.key,
  required super.value,
  required super.onChanged,
  required Color activeTrackColor,
  required Color inactiveTrackColor,
  super.activeThumbImage,
  super.onActiveThumbImageError,
  super.inactiveThumbImage,
  super.onInactiveThumbImageError,
  super.thumbColor,
  super.trackColor,
  super.trackOutlineWidth,
  super.thumbIcon,
  super.materialTapTargetSize,
  super.dragStartBehavior,
  super.mouseCursor,
  super.focusColor,
  super.hoverColor,
  super.overlayColor,
  super.splashRadius,
  super.focusNode,
  super.onFocusChange,
  super.autofocus,
  super.padding,
}) : super(
       activeThumbColor: Colors.white,
       activeTrackColor: activeTrackColor,
       inactiveThumbColor: Colors.white,
       inactiveTrackColor: inactiveTrackColor,
       trackOutlineColor: WidgetStateProperty.all(Colors.transparent),
     );