FlutterSwitch constructor

const FlutterSwitch({
  1. Key? key,
  2. required bool value,
  3. required ValueChanged<bool> onToggle,
  4. Color activeColor = Colors.blue,
  5. Color inactiveColor = Colors.grey,
  6. Color activeTextColor = Colors.white70,
  7. Color inactiveTextColor = Colors.white70,
  8. Color toggleColor = Colors.white,
  9. Color? activeToggleColor,
  10. Color? inactiveToggleColor,
  11. double width = 70.0,
  12. double height = 35.0,
  13. double toggleSize = 25.0,
  14. double valueFontSize = 16.0,
  15. double borderRadius = 20.0,
  16. double padding = 4.0,
  17. bool showOnOff = false,
  18. String? activeText,
  19. String? inactiveText,
  20. FontWeight? activeTextFontWeight,
  21. FontWeight? inactiveTextFontWeight,
  22. BoxBorder? switchBorder,
  23. BoxBorder? activeSwitchBorder,
  24. BoxBorder? inactiveSwitchBorder,
  25. BoxBorder? toggleBorder,
  26. BoxBorder? activeToggleBorder,
  27. BoxBorder? inactiveToggleBorder,
  28. Widget? activeIcon,
  29. Widget? inactiveIcon,
  30. Duration duration = const Duration(milliseconds: 200),
  31. bool disabled = false,
})

Creates a material design switch.

The following arguments are required:

  • value determines whether this switch is on or off.
  • onToggle is called when the user toggles the switch on or off.

Implementation

const FlutterSwitch({
  Key? key,
  required this.value,
  required this.onToggle,
  this.activeColor = Colors.blue,
  this.inactiveColor = Colors.grey,
  this.activeTextColor = Colors.white70,
  this.inactiveTextColor = Colors.white70,
  this.toggleColor = Colors.white,
  this.activeToggleColor,
  this.inactiveToggleColor,
  this.width = 70.0,
  this.height = 35.0,
  this.toggleSize = 25.0,
  this.valueFontSize = 16.0,
  this.borderRadius = 20.0,
  this.padding = 4.0,
  this.showOnOff = false,
  this.activeText,
  this.inactiveText,
  this.activeTextFontWeight,
  this.inactiveTextFontWeight,
  this.switchBorder,
  this.activeSwitchBorder,
  this.inactiveSwitchBorder,
  this.toggleBorder,
  this.activeToggleBorder,
  this.inactiveToggleBorder,
  this.activeIcon,
  this.inactiveIcon,
  this.duration = const Duration(milliseconds: 200),
  this.disabled = false,
})  : assert(
          (switchBorder == null || activeSwitchBorder == null) &&
              (switchBorder == null || inactiveSwitchBorder == null),
          'Cannot provide switchBorder when an activeSwitchBorder or inactiveSwitchBorder was given\n'
          'To give the switch a border, use "activeSwitchBorder: border" or "inactiveSwitchBorder: border".'),
      assert(
          (toggleBorder == null || activeToggleBorder == null) &&
              (toggleBorder == null || inactiveToggleBorder == null),
          'Cannot provide toggleBorder when an activeToggleBorder or inactiveToggleBorder was given\n'
          'To give the toggle a border, use "activeToggleBorder: color" or "inactiveToggleBorder: color".'),
      super(key: key);