Allow using the ports_tab component as a port selection dialog

This commit is contained in:
2024-08-28 23:10:37 +02:00
parent 0997e067d9
commit 340d6033ef

View File

@ -7,8 +7,14 @@ enum MenuAction { edit, delete }
class PortsTab extends StatefulWidget { class PortsTab extends StatefulWidget {
final mixer.MixerState mixerState; final mixer.MixerState mixerState;
final void Function(Map<String, Object> data) sendAction; final void Function(Map<String, Object> data) sendAction;
final bool Function(mixer.Port port, bool isOutput)? filter;
final void Function(mixer.Port port)? selectionCallback;
const PortsTab( const PortsTab(
{super.key, required this.mixerState, required this.sendAction}); {super.key,
required this.mixerState,
required this.sendAction,
this.filter,
this.selectionCallback});
@override @override
State<PortsTab> createState() => _PortsTabState(); State<PortsTab> createState() => _PortsTabState();
@ -76,11 +82,14 @@ class _PortsTabState extends State<PortsTab> {
const SizedBox(height: 10), const SizedBox(height: 10),
...[...widget.mixerState.inputs, ...widget.mixerState.outputs] ...[...widget.mixerState.inputs, ...widget.mixerState.outputs]
.indexed .indexed
.where((elem) { .where((elem) => widget.filter != null
return elem.$2.name ? widget.filter!(
elem.$2, (elem.$1 >= widget.mixerState.inputs.length))
: true)
.where((elem) => elem.$2.name
.toLowerCase() .toLowerCase()
.contains(searchText.toLowerCase()); .contains(searchText.toLowerCase()))
}).map( .map(
(elem) => Card( (elem) => Card(
child: ListTile( child: ListTile(
leading: (elem.$1 >= widget.mixerState.inputs.length) leading: (elem.$1 >= widget.mixerState.inputs.length)
@ -88,6 +97,9 @@ class _PortsTabState extends State<PortsTab> {
: const Icon(Icons.mic_none_outlined), : const Icon(Icons.mic_none_outlined),
title: Text(elem.$2.name), title: Text(elem.$2.name),
subtitle: Text('Backend: ${elem.$2.properties.backend}'), subtitle: Text('Backend: ${elem.$2.properties.backend}'),
onTap: widget.selectionCallback != null
? () => widget.selectionCallback!(elem.$2)
: null,
trailing: PopupMenuButton<MenuAction>( trailing: PopupMenuButton<MenuAction>(
tooltip: "More Options", tooltip: "More Options",
onSelected: (MenuAction item) { onSelected: (MenuAction item) {