CycleButton<T> constructor

CycleButton<T>({
  1. Key? key,
  2. required List<T> values,
  3. required Widget builder(
    1. BuildContext,
    2. T
    ),
  4. required T initialValue,
  5. dynamic onChanged(
    1. T value
    )?,
  6. ButtonStyle style = const ButtonStyle.ghost(),
  7. ButtonSize size = ButtonSize.normal,
  8. ButtonDensity density = ButtonDensity.icon,
  9. ButtonShape shape = ButtonShape.rectangle,
  10. FocusNode? focusNode,
  11. bool disableTransition = false,
  12. ValueChanged<bool>? onHover,
  13. ValueChanged<bool>? onFocus,
  14. 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');