diff --git a/lib/ports_tab.dart b/lib/ports_tab.dart index 9242257..59fe1af 100644 --- a/lib/ports_tab.dart +++ b/lib/ports_tab.dart @@ -15,6 +15,9 @@ class PortsTab extends StatefulWidget { } class _PortsTabState extends State { + final searchController = TextEditingController(); + String searchText = ""; + void onEditPort(mixer.Port port) { CreatePortDialog().show(context, widget.sendAction, port, false); } @@ -48,48 +51,75 @@ class _PortsTabState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: Column( - children: [...widget.mixerState.inputs, ...widget.mixerState.outputs] - .indexed - .map( - (elem) => Card( - child: ListTile( - leading: (elem.$1 >= widget.mixerState.inputs.length) - ? const Icon(Icons.speaker_outlined) - : const Icon(Icons.mic_none_outlined), - title: Text(elem.$2.name), - subtitle: Text('Backend: ${elem.$2.properties.backend}'), - trailing: PopupMenuButton( - tooltip: "More Options", - onSelected: (MenuAction item) { - switch (item) { - case MenuAction.edit: - onEditPort(elem.$2); - case MenuAction.delete: - onDeletePort(elem.$2); - } - }, - itemBuilder: (BuildContext context) => - >[ - const PopupMenuItem( - value: MenuAction.edit, - child: ListTile( - leading: Icon(Icons.mode_edit), - title: Text('Edit'), - ), + children: [ + TextField( + decoration: InputDecoration( + prefixIcon: const Icon(Icons.search), + suffixIcon: IconButton( + icon: const Icon(Icons.clear), + onPressed: () { + setState(() { + searchController.text = ""; + searchText = ""; + }); + }, + ), + labelText: 'Search', + border: const OutlineInputBorder(), + ), + onChanged: (val) { + setState(() { + searchText = val; + }); + }, + controller: searchController), + const SizedBox(height: 10), + ...[...widget.mixerState.inputs, ...widget.mixerState.outputs] + .indexed + .where((elem) { + return elem.$2.name + .toLowerCase() + .contains(searchText.toLowerCase()); + }).map( + (elem) => Card( + child: ListTile( + leading: (elem.$1 >= widget.mixerState.inputs.length) + ? const Icon(Icons.speaker_outlined) + : const Icon(Icons.mic_none_outlined), + title: Text(elem.$2.name), + subtitle: Text('Backend: ${elem.$2.properties.backend}'), + trailing: PopupMenuButton( + tooltip: "More Options", + onSelected: (MenuAction item) { + switch (item) { + case MenuAction.edit: + onEditPort(elem.$2); + case MenuAction.delete: + onDeletePort(elem.$2); + } + }, + itemBuilder: (BuildContext context) => + >[ + const PopupMenuItem( + value: MenuAction.edit, + child: ListTile( + leading: Icon(Icons.mode_edit), + title: Text('Edit'), ), - const PopupMenuItem( - value: MenuAction.delete, - child: ListTile( - leading: Icon(Icons.delete), - title: Text('Delete'), - ), + ), + const PopupMenuItem( + value: MenuAction.delete, + child: ListTile( + leading: Icon(Icons.delete), + title: Text('Delete'), ), - ], - ), + ), + ], ), ), - ) - .toList(), + ), + ) + ], ), ), );