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