CycleButton<T> constructor
CycleButton<T> ({
- Key? key,
- required List<
T> values, - required Widget builder(
- BuildContext,
- T
- required T initialValue,
- dynamic onChanged(
- T value
- ButtonStyle style = const ButtonStyle.ghost(),
- ButtonSize size = ButtonSize.normal,
- ButtonDensity density = ButtonDensity.icon,
- ButtonShape shape = ButtonShape.rectangle,
- FocusNode? focusNode,
- bool disableTransition = false,
- ValueChanged<
bool> ? onHover, - ValueChanged<
bool> ? onFocus, - bool? enableFeedback,
Creates a CycleButton with the given values and callbacks.
Initializes a generic CycleButton using the provided style
, which defaults
to ButtonStyle.ghost() for subtle input toggling. The values
list must
have at least one entry, and initialValue
must exist within it to ensure
valid starting state.
Suitable for custom styling in input scenarios, such as cycling visibility
modes in a ArcaneInput toolbar. Assertions enforce non-empty values
and valid initialValue
at construction time, preventing runtime errors.
Usage example:
CycleButton<String>(
values: ['off', 'low', 'high'],
initialValue: 'off',
builder: (context, value) => Text(value.toUpperCase()),
style: ButtonStyle.outline(),
onChanged: (newValue) => print('Switched to $newValue'),
)
Implementation
CycleButton({
super.key,
required this.values,
required this.builder,
required this.initialValue,
this.onChanged,
this.style = const ButtonStyle.ghost(),
this.size = ButtonSize.normal,
this.density = ButtonDensity.icon,
this.shape = ButtonShape.rectangle,
this.focusNode,
this.disableTransition = false,
this.onHover,
this.onFocus,
this.enableFeedback,
}) : assert(values.isNotEmpty, 'Values map must not be empty'),
assert(values.contains(initialValue),
'Initial value must be a key in the values map');