ControlledToggle constructor

const ControlledToggle({
  1. Key? key,
  2. ToggleController? controller,
  3. bool? initialValue,
  4. ValueChanged<bool>? onChanged,
  5. bool enabled = true,
  6. required Widget child,
  7. ButtonStyle style = const ButtonStyle.ghost(),
})

Creates a ControlledToggle widget.

Parameters:

  • controller (ToggleController?, optional): External state controller.
  • initialValue (bool?, optional): Initial state for uncontrolled mode.
  • onChanged (ValueChanged
  • enabled (bool, default: true): Whether the toggle is interactive.
  • child (Widget, required): Content to display in the toggle button.
  • style (ButtonStyle, default: ButtonStyle.ghost()): Visual styling.

Example:

ControlledToggle(
  initialValue: false,
  onChanged: (value) => print('Toggled: $value'),
  enabled: true,
  style: ButtonStyle.secondary(),
  child: Text('Toggle Me'),
);

Implementation

const ControlledToggle({
  super.key,
  this.controller,
  this.initialValue,
  this.onChanged,
  this.enabled = true,
  required this.child,
  this.style = const ButtonStyle.ghost(),
});