Implement creating, deleting and editing of ports

This commit is contained in:
2024-07-03 10:17:29 +02:00
parent 47d9443f48
commit 639527a49a
4 changed files with 258 additions and 20 deletions

54
lib/select_button.dart Normal file
View 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(),
);
}
}