133 lines
4.2 KiB
Dart
133 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:gomix_flutter/mixer_state.dart' as mixer;
|
|
|
|
class MixingCard extends StatefulWidget {
|
|
final mixer.Port port;
|
|
final Function sendAction;
|
|
final bool isOutput;
|
|
const MixingCard(
|
|
{super.key,
|
|
required this.port,
|
|
required this.sendAction,
|
|
this.isOutput = false});
|
|
|
|
@override
|
|
State<MixingCard> createState() => _MixingCardState();
|
|
}
|
|
|
|
class _MixingCardState extends State<MixingCard> {
|
|
double _sliderValue = 0;
|
|
int _debounceTimer = 0;
|
|
bool _sliderActive = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_sliderValue = widget.port.state.volume;
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(MixingCard oldWidget) {
|
|
if (_sliderActive) return;
|
|
_sliderValue = widget.port.state.volume;
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var labelStyle = Theme.of(context)
|
|
.textTheme
|
|
.labelLarge
|
|
?.apply(color: Theme.of(context).colorScheme.primary);
|
|
return Card(
|
|
margin: const EdgeInsets.all(0),
|
|
shadowColor: Colors.transparent,
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 15, right: 15, top: 15),
|
|
child: Row(
|
|
children: [
|
|
Expanded(child: Text(widget.port.name, style: labelStyle)),
|
|
SizedBox(
|
|
height: 40,
|
|
width: 40,
|
|
child: IconButton.filledTonal(
|
|
iconSize: 20,
|
|
isSelected: widget.port.state.mute,
|
|
onPressed: () {
|
|
widget.sendAction({
|
|
"method": "setPortState",
|
|
"UUID": widget.port.uuid,
|
|
"stateData": {"mute": !widget.port.state.mute}
|
|
});
|
|
},
|
|
icon: widget.isOutput
|
|
? (widget.port.state.mute
|
|
? const Icon(Icons.volume_off_outlined)
|
|
: const Icon(Icons.volume_up_outlined))
|
|
: (widget.port.state.mute
|
|
? const Icon(Icons.mic_off_outlined)
|
|
: const Icon(Icons.mic_none_outlined)),
|
|
),
|
|
),
|
|
const SizedBox(width: 5),
|
|
SizedBox(
|
|
height: 40,
|
|
width: 40,
|
|
child: IconButton.outlined(
|
|
iconSize: 20,
|
|
isSelected: false,
|
|
onPressed: () {},
|
|
icon: const Icon(Icons.unfold_more)))
|
|
],
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: MediaQuery.of(context).size.width + 180,
|
|
child: Slider(
|
|
value: _sliderValue,
|
|
min: 0,
|
|
max: 4,
|
|
label: _sliderValue.toStringAsFixed(2),
|
|
onChangeStart: ((val) {
|
|
_sliderActive = true;
|
|
}),
|
|
onChangeEnd: ((val) {
|
|
// Send the current state to make sure we
|
|
// don't miss the last value due to the debounce
|
|
widget.sendAction({
|
|
"method": "setPortState",
|
|
"UUID": widget.port.uuid,
|
|
"stateData": {"volume": val}
|
|
});
|
|
// Make sure the slider value is still correct
|
|
// after suppressing updates
|
|
_sliderActive = false;
|
|
setState(() {
|
|
_sliderValue = widget.port.state.volume;
|
|
});
|
|
}),
|
|
onChanged: (val) {
|
|
setState(() {
|
|
_sliderValue = val;
|
|
});
|
|
if (DateTime.now().millisecondsSinceEpoch - _debounceTimer <
|
|
30) {
|
|
return;
|
|
}
|
|
_debounceTimer = DateTime.now().millisecondsSinceEpoch;
|
|
widget.sendAction({
|
|
"method": "setPortState",
|
|
"UUID": widget.port.uuid,
|
|
"stateData": {"volume": val}
|
|
});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|