summaryrefslogtreecommitdiffstats
path: root/lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart
blob: fa76bd84b0de21d5bf927250e604732bc3b27d00 (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
// SPDX-License-Identifier: Apache-2.0

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/gauges/gauge_props.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/gauges/gauge_widget.dart';
import 'package:flutter_cluster_dashboard/vehicle-signals/vehicle_status_provider.dart';

class RPMGauge extends HookConsumerWidget {
  final double screenHeight;
  final GaugeColors? gaugeColor;
  const RPMGauge({Key? key, required this.screenHeight, this.gaugeColor})
      : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final double rpm = ref.watch(vehicleStatusProvider.select((p) => p.rpm));

    const double minRPM = 0;
    const double maxRPM = 8000;
    const Duration sweepDuration = Duration(milliseconds: 200);

    final animationController = useAnimationController(
      lowerBound: minRPM,
      upperBound: maxRPM,
    )..animateTo(rpm,
        duration: sweepDuration, curve: Curves.linearToEaseOut);
    return AnimatedBuilder(
        animation: animationController,
        builder: (context, child) {
          return Padding(
            padding: const EdgeInsets.all(8.0),
            child: CustomGauge(
              size: (248 * screenHeight) / 480,
              low: minRPM,
              high: maxRPM,
              mainValue: animationController.value,
              label: "rpm",
              zeroTickLabel: minRPM.toInt().toString(),
              maxTickLabel: maxRPM.toInt().toString(),
              inPrimaryColor: gaugeColor?.inPrimary,
              outPrimaryColor: gaugeColor?.outPrimary,
              secondaryColor: gaugeColor?.secondary,
            ),
          );
        });
  }
}