Toggle constructor

const Toggle({
  1. Key? key,
  2. required bool value,
  3. ValueChanged<bool>? onChanged,
  4. required Widget child,
  5. bool? enabled,
  6. ButtonStyle style = const ButtonStyle.ghost(),
})

Creates a Toggle.

The toggle button maintains its own state and calls onChanged when the state changes. Uses ghost button styling by default.

Parameters:

  • value (bool, required): current toggle state
  • onChanged (ValueChanged
  • child (Widget, required): content displayed inside the button
  • enabled (bool?, optional): whether button is interactive
  • style (ButtonStyle, default: ghost): button styling

Example:

Toggle(
  value: isToggled,
  onChanged: (value) => setState(() => isToggled = value),
  child: Row(
    children: [
      Icon(Icons.notifications),
      Text('Notifications'),
    ],
  ),
)

Implementation

const Toggle({
  super.key,
  required this.value,
  this.onChanged,
  required this.child,
  this.enabled,
  this.style = const ButtonStyle.ghost(),
});