import 'package:flutter/material.dart'; class SelectButton extends StatefulWidget { final List options; final int defaultIndex; final bool allowNull; final bool isDisabled; final void Function(int selection) onChange; const SelectButton( {super.key, required this.options, this.defaultIndex = 0, this.allowNull = true, this.isDisabled = false, required this.onChange}); @override State createState() => _SelectButtonState(); } class _SelectButtonState extends State { int _selection = 0; @override void initState() { super.initState(); _selection = widget.defaultIndex; } @override Widget build(BuildContext context) { return Wrap( spacing: 5.0, children: List.generate( widget.options.length, (int index) { return ChoiceChip( label: Text(widget.options[index]), selected: _selection == index, onSelected: (bool selected) { if (widget.isDisabled) return; if (!selected && !widget.allowNull) return; setState(() { _selection = selected ? index : -1; widget.onChange(_selection); }); }, ); }, ).toList(), ); } }