aboutsummaryrefslogtreecommitdiffstats
path: root/lib/volume_slider.dart
blob: 06654911eff69acc013789f8c0f19fc1227abc8d (plain)
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
50
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_providers.dart';
import 'package:flutter_homescreen/vehicle-signals/vss_path.dart';
import 'package:flutter_homescreen/vehicle-signals/viss_methods.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());
          WebSocket? s = ref.read(VISServerSocketProvider).socket;
          if (s != null) {
            VISS.set(
                s, ref, VSSPath.vehicleMediaVolume, value.toInt().toString());
          }
        });
  }
}