Toggle constructor
const
Toggle({
- Key? key,
- required bool value,
- ValueChanged<
bool> ? onChanged, - required Widget child,
- bool? enabled,
- 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 stateonChanged(ValueChangedchild(Widget, required): content displayed inside the buttonenabled(bool?, optional): whether button is interactivestyle(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(),
});