1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import 'dart:io';
import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_homescreen/vehicle-signals/vss_signal_providers.dart';
import 'package:flutter_homescreen/vehicle-signals/vss_path.dart';
import 'package:flutter_homescreen/vehicle-signals/vss_provider.dart';
class VolumeSlider extends ConsumerWidget {
final Color thumbColor;
final Color activeColor;
final Color inactiveColor;
final RestartableTimer? activityTimer;
VolumeSlider(
{Key? key,
required this.thumbColor,
required this.activeColor,
required this.inactiveColor,
required this.activityTimer})
: super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
final signal = ref.watch(vehicleSignalMediaVolumeProvider);
return Slider(
thumbColor: thumbColor,
activeColor: activeColor,
inactiveColor: inactiveColor,
value: signal.volume.toDouble(),
max: 100,
label: "Volume",
onChangeStart: (value) {
activityTimer?.cancel();
},
onChangeEnd: (value) {
activityTimer?.reset();
},
onChanged: (value) {
ref
.read(vehicleSignalMediaVolumeProvider.notifier)
.update(volume: value.toInt());
var vss = ref.read(vssClientProvider);
if (vss != null) {
vss.setUint32(VSSPath.vehicleMediaVolume, value.toInt());
}
});
}
}
|