✨ Implement creating, deleting and editing of ports
This commit is contained in:
54
lib/select_button.dart
Normal file
54
lib/select_button.dart
Normal file
@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SelectButton extends StatefulWidget {
|
||||
final List<String> 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<SelectButton> createState() => _SelectButtonState();
|
||||
}
|
||||
|
||||
class _SelectButtonState extends State<SelectButton> {
|
||||
int _selection = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selection = widget.defaultIndex;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Wrap(
|
||||
spacing: 5.0,
|
||||
children: List<Widget>.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(),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user