From 80a4f8d75a66c22a23e825d4c0fb4065e2e58cb8 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sun, 24 Sep 2023 12:45:03 -0400 Subject: Rework to use KUKSA.val databroker gRPC API Rework to move from the WebSocket API with the older KUKSA.val server to the gRPC "VAL" API of the databroker. Changes include: - All VISS WebSocket API code has been removed, and the signal providers replumbed to be driven by a new VssClient class with a dashboard-specific child class to hold all the gRPC API handling. - The generated code for the VAL API and its dependencies has been checked in under lib/generated, as there still does not seem to be a good way to generate it during the Flutter build. - The "flutter-" prefix has been dropped from the configuration file name (i.e. it's now just "cluster-dashboard.yaml") to match the naming used for the other Flutter applications. The authorization token field name has been renamed to "authorization", and there are new "use-tls" and "ca-certificate" configuration fields. TLS is disabled by default for now, and the default CA certificate is /etc/kuksa.val/CA.pem. - Bumped minimum SDK version to 2.18 in pubspec.yaml to enable "super" keyword support. This matches what the version was set to in the other applications. - The unused navigation support has been removed to simplify maintenance, as it is more likely that it will be replaced with something else in the future than fixed to be usable. - Removed .dart_tool generated output that had been checked in, and added .gitignore file from flutter-homescreen so that things will hopefully stay clean in the future. Since pubspec.lock is not checked in here, it has also been added to .gitignore. Bug-AGL: SPEC-4762 Signed-off-by: Scott Murray Change-Id: Id35c569cdbb8476a527717ece7b4bb369c4874b7 --- lib/screen/widgets/gauges/gauge_props.dart | 48 +++++++++ lib/screen/widgets/gauges/gauge_widget.dart | 109 +++++++++++++++++++++ .../gauges/rpm_gauge_animation_wrapper.dart | 50 ++++++++++ .../gauges/speed_gauge_animation_wrapper.dart | 65 ++++++++++++ lib/screen/widgets/guages/guage_props.dart | 48 --------- lib/screen/widgets/guages/guage_widget.dart | 109 --------------------- .../guages/rpm_guage_animation_wrapper.dart | 51 ---------- .../guages/speed_guage_animation_wrapper.dart | 66 ------------- lib/screen/widgets/left_bar.dart | 7 +- lib/screen/widgets/right_bar.dart | 7 +- lib/screen/widgets/signals.dart | 43 ++++---- 11 files changed, 304 insertions(+), 299 deletions(-) create mode 100644 lib/screen/widgets/gauges/gauge_props.dart create mode 100644 lib/screen/widgets/gauges/gauge_widget.dart create mode 100644 lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart create mode 100644 lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart delete mode 100644 lib/screen/widgets/guages/guage_props.dart delete mode 100644 lib/screen/widgets/guages/guage_widget.dart delete mode 100644 lib/screen/widgets/guages/rpm_guage_animation_wrapper.dart delete mode 100644 lib/screen/widgets/guages/speed_guage_animation_wrapper.dart (limited to 'lib/screen/widgets') diff --git a/lib/screen/widgets/gauges/gauge_props.dart b/lib/screen/widgets/gauges/gauge_props.dart new file mode 100644 index 0000000..51dba51 --- /dev/null +++ b/lib/screen/widgets/gauges/gauge_props.dart @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'dart:math'; +import 'package:flutter/material.dart'; + +class GaugeProps { + static GaugeColors normalModeColor = GaugeColors( + inPrimary: const Color.fromARGB(255, 67, 67, 67), + outPrimary: const Color.fromARGB(255, 120, 120, 120), + secondary: const Color.fromARGB(156, 226, 226, 200), + ); + static GaugeColors sportModeColor = GaugeColors( + inPrimary: Colors.deepPurple, + outPrimary: Colors.blue, + secondary: const Color.fromARGB(214, 202, 202, 202)); + static GaugeColors ecoModeColor = GaugeColors( + inPrimary: const Color.fromARGB(255, 85, 165, 87), + outPrimary: const Color.fromARGB(255, 40, 92, 42), + secondary: const Color.fromARGB(202, 194, 238, 195)); + static double majorAngle = 260; + static double majorAngleRad = 260 * (pi / 180); + static double minorAngle = 360 - majorAngle; + static Color bgColor = const Color.fromARGB(255, 0, 0, 0); + static const leftLowColor = Color(0x000000ff); + static const leftHighColor = Color(0x00ff0000); + + static double degToRad(double deg) => deg * (pi / 180.0); + static TextStyle gearIconStyle(screenHeight) { + return TextStyle( + color: const Color.fromARGB(255, 84, 83, 83), + fontSize: (20 * screenHeight) / 480, + fontWeight: FontWeight.bold); + } + + static TextStyle activeGearIconStyle(screenHeight) { + return TextStyle( + color: Colors.white, + fontSize: (20 * screenHeight) / 480, + fontWeight: FontWeight.bold); + } +} + +class GaugeColors { + Color? inPrimary; + Color? outPrimary; + Color? secondary; + GaugeColors({this.inPrimary, this.outPrimary, this.secondary}); +} diff --git a/lib/screen/widgets/gauges/gauge_widget.dart b/lib/screen/widgets/gauges/gauge_widget.dart new file mode 100644 index 0000000..c302953 --- /dev/null +++ b/lib/screen/widgets/gauges/gauge_widget.dart @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'dart:math'; +import 'package:flutter/material.dart'; +import 'package:flutter_cluster_dashboard/screen/paints/gauge_paint.dart'; +import 'package:flutter_cluster_dashboard/screen/widgets/gauges/gauge_props.dart'; + +class CustomGauge extends StatelessWidget { + const CustomGauge({ + Key? key, + required this.mainValue, + required this.low, + required this.high, + required this.label, + this.zeroTickLabel, + this.maxTickLabel, + this.distanceBWTicks, + this.size, + this.distLabelTop, + this.distMainTop, + this.distTicksBottom, + this.inPrimaryColor, + this.outPrimaryColor, + this.secondaryColor, + }) : super(key: key); + + final double mainValue; + final double low; + final double high; + final String label; + final String? zeroTickLabel; + final String? maxTickLabel; + final double? distanceBWTicks; + final double? distTicksBottom; + final double? distMainTop; + final double? distLabelTop; + final double? size; + final Color? outPrimaryColor; + final Color? inPrimaryColor; + final Color? secondaryColor; + + @override + Widget build(BuildContext context) { + TextStyle tickStyle = TextStyle( + color: Colors.white, + fontSize: ((26 / 400) * (size ?? 400)), + fontWeight: FontWeight.bold); //20 + TextStyle mainValueTextStyle = TextStyle( + color: Colors.white, + fontSize: ((85 / 400) * (size ?? 400)), + fontWeight: FontWeight.bold); //65 + TextStyle labelTextStyle = TextStyle( + color: Colors.white, + fontSize: ((26 / 400) * (size ?? 400)), + fontWeight: FontWeight.normal); //20 + return SizedBox( + width: size ?? 400, + height: size ?? 400, + child: Stack( + alignment: Alignment.topCenter, + children: [ + // Gauge painter + Positioned( + top: 0, + child: Transform.rotate( + angle: (pi / 2) + (GaugeProps.minorAngle * (pi / 360.0)), + child: CustomPaint( + size: Size(size ?? 400, size ?? 400), + painter: GaugePainter( + low: low, + high: high, + currentSpeed: mainValue, + inPrimaryColor: inPrimaryColor, + outPrimaryColor: outPrimaryColor, + secondaryColor: secondaryColor, + ), + ), + ), + ), + // Gauge Label + Positioned( + top: distLabelTop ?? ((100 / 400) * (size ?? 400)), + child: Text(label, style: labelTextStyle), + ), + // Gauge Main Value + Positioned( + top: distMainTop ?? ((150 / 400) * (size ?? 400)), + child: Text("${mainValue.toInt()}", style: mainValueTextStyle), + ), + // Gauge Ticks value + Positioned( + bottom: distTicksBottom ?? ((80 / 400) * (size ?? 400)), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(zeroTickLabel ?? "", style: tickStyle), + SizedBox( + width: (size != null) + ? ((180 * size!) / 400) + : (distanceBWTicks ?? 180)), + Text(maxTickLabel ?? "", style: tickStyle) + ], + ), + ), + ], + ), + ); + } +} diff --git a/lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart b/lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart new file mode 100644 index 0000000..fa76bd8 --- /dev/null +++ b/lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart @@ -0,0 +1,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, + ), + ); + }); + } +} diff --git a/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart b/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart new file mode 100644 index 0000000..dfa4277 --- /dev/null +++ b/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'package:flutter/material.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 SpeedGauge extends HookConsumerWidget { + final double screenHeight; + final GaugeColors? gaugeColor; + const SpeedGauge({Key? key, required this.screenHeight, this.gaugeColor}) + : super(key: key); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final double speed = ref.watch(vehicleStatusProvider.select((p) => p.speed)); + final String units = ref.watch(vehicleStatusProvider.select((p) => p.vehicleDistanceUnit)); + + const double minSpeed = 0; + const double maxSpeed = 240; + const Duration sweepDuration = Duration(milliseconds: 200); + double speedScaling = (units == "mi") ? 0.621504 : 1.0; + + final animationController = useAnimationController( + lowerBound: minSpeed, + upperBound: maxSpeed, + )..animateTo(speedScaling * speed, + 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: minSpeed, + high: maxSpeed, + mainValue: animationController.value, + label: (units == "mi") ? "mph" : "Km/h", + zeroTickLabel: minSpeed.toInt().toString(), + maxTickLabel: maxSpeed.toInt().toString(), + inPrimaryColor: gaugeColor?.inPrimary, + outPrimaryColor: gaugeColor?.outPrimary, + secondaryColor: gaugeColor?.secondary, + ), + ); + }); + } +} + +final gaugeColorProvider = Provider.family((ref, mode) { + switch (mode) { + case "normal": + return GaugeColors(inPrimary: Colors.red); + case "sports": + return GaugeColors(inPrimary: Colors.blue); + case "eco": + return GaugeColors(inPrimary: Colors.green); + default: + return GaugeColors(); + } +}); diff --git a/lib/screen/widgets/guages/guage_props.dart b/lib/screen/widgets/guages/guage_props.dart deleted file mode 100644 index bb56a31..0000000 --- a/lib/screen/widgets/guages/guage_props.dart +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -import 'dart:math'; -import 'package:flutter/material.dart'; - -class GuageProps { - static GuageColors normalModeColor = GuageColors( - inPrimary: const Color.fromARGB(255, 67, 67, 67), - outPrimary: const Color.fromARGB(255, 120, 120, 120), - secondary: const Color.fromARGB(156, 226, 226, 200), - ); - static GuageColors sportModeColor = GuageColors( - inPrimary: Colors.deepPurple, - outPrimary: Colors.blue, - secondary: const Color.fromARGB(214, 202, 202, 202)); - static GuageColors ecoModeColor = GuageColors( - inPrimary: const Color.fromARGB(255, 85, 165, 87), - outPrimary: const Color.fromARGB(255, 40, 92, 42), - secondary: const Color.fromARGB(202, 194, 238, 195)); - static double majorAngle = 260; - static double majorAngleRad = 260 * (pi / 180); - static double minorAngle = 360 - majorAngle; - static Color bgColor = const Color.fromARGB(255, 0, 0, 0); - static const leftLowColor = Color(0x000000ff); - static const leftHighColor = Color(0x00ff0000); - - static double degToRad(double deg) => deg * (pi / 180.0); - static TextStyle gearIconStyle(screenHeight) { - return TextStyle( - color: const Color.fromARGB(255, 84, 83, 83), - fontSize: (20 * screenHeight) / 480, - fontWeight: FontWeight.bold); - } - - static TextStyle activeGearIconStyle(screenHeight) { - return TextStyle( - color: Colors.white, - fontSize: (20 * screenHeight) / 480, - fontWeight: FontWeight.bold); - } -} - -class GuageColors { - Color? inPrimary; - Color? outPrimary; - Color? secondary; - GuageColors({this.inPrimary, this.outPrimary, this.secondary}); -} diff --git a/lib/screen/widgets/guages/guage_widget.dart b/lib/screen/widgets/guages/guage_widget.dart deleted file mode 100644 index fa43958..0000000 --- a/lib/screen/widgets/guages/guage_widget.dart +++ /dev/null @@ -1,109 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -import 'dart:math'; -import 'package:flutter/material.dart'; -import 'package:flutter_cluster_dashboard/screen/paints/guage_paint.dart'; -import 'package:flutter_cluster_dashboard/screen/widgets/guages/guage_props.dart'; - -class CustomGuage extends StatelessWidget { - const CustomGuage({ - Key? key, - required this.mainValue, - required this.low, - required this.high, - required this.label, - this.zeroTickLabel, - this.maxTickLabel, - this.distanceBWTicks, - this.size, - this.distLabelTop, - this.distMainTop, - this.distTicksBottom, - this.inPrimaryColor, - this.outPrimaryColor, - this.secondaryColor, - }) : super(key: key); - - final double mainValue; - final double low; - final double high; - final String label; - final String? zeroTickLabel; - final String? maxTickLabel; - final double? distanceBWTicks; - final double? distTicksBottom; - final double? distMainTop; - final double? distLabelTop; - final double? size; - final Color? outPrimaryColor; - final Color? inPrimaryColor; - final Color? secondaryColor; - - @override - Widget build(BuildContext context) { - TextStyle tickStyle = TextStyle( - color: Colors.white, - fontSize: ((26 / 400) * (size ?? 400)), - fontWeight: FontWeight.bold); //20 - TextStyle mainValueTextStyle = TextStyle( - color: Colors.white, - fontSize: ((85 / 400) * (size ?? 400)), - fontWeight: FontWeight.bold); //65 - TextStyle labelTextStyle = TextStyle( - color: Colors.white, - fontSize: ((26 / 400) * (size ?? 400)), - fontWeight: FontWeight.normal); //20 - return SizedBox( - width: size ?? 400, - height: size ?? 400, - child: Stack( - alignment: Alignment.topCenter, - children: [ - // Guage painter - Positioned( - top: 0, - child: Transform.rotate( - angle: (pi / 2) + (GuageProps.minorAngle * (pi / 360.0)), - child: CustomPaint( - size: Size(size ?? 400, size ?? 400), - painter: GuagePainter( - low: low, - high: high, - currentSpeed: mainValue, - inPrimaryColor: inPrimaryColor, - outPrimaryColor: outPrimaryColor, - secondaryColor: secondaryColor, - ), - ), - ), - ), - // Guage Label - Positioned( - top: distLabelTop ?? ((100 / 400) * (size ?? 400)), - child: Text(label, style: labelTextStyle), - ), - // Guage Main Value - Positioned( - top: distMainTop ?? ((150 / 400) * (size ?? 400)), - child: Text("${mainValue.toInt()}", style: mainValueTextStyle), - ), - // Guage Ticks value - Positioned( - bottom: distTicksBottom ?? ((80 / 400) * (size ?? 400)), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(zeroTickLabel ?? "", style: tickStyle), - SizedBox( - width: (size != null) - ? ((180 * size!) / 400) - : (distanceBWTicks ?? 180)), - Text(maxTickLabel ?? "", style: tickStyle) - ], - ), - ), - ], - ), - ); - } -} diff --git a/lib/screen/widgets/guages/rpm_guage_animation_wrapper.dart b/lib/screen/widgets/guages/rpm_guage_animation_wrapper.dart deleted file mode 100644 index 95403dd..0000000 --- a/lib/screen/widgets/guages/rpm_guage_animation_wrapper.dart +++ /dev/null @@ -1,51 +0,0 @@ -// 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/guages/guage_props.dart'; -import 'package:flutter_cluster_dashboard/screen/widgets/guages/guage_widget.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_model.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_provider.dart'; - -class RPMGauge extends HookConsumerWidget { - final double screenHeight; - final GuageColors? guageColor; - const RPMGauge({Key? key, required this.screenHeight, this.guageColor}) - : super(key: key); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final VehicleSignal vehicle = ref.watch(vehicleSignalProvider); - - const double minRPM = 0; - const double maxRPM = 8000; - const Duration sweepDuration = Duration(milliseconds: 200); - - final animationController = useAnimationController( - lowerBound: minRPM, - upperBound: maxRPM, - )..animateTo(vehicle.rpm, - duration: sweepDuration, curve: Curves.linearToEaseOut); - return AnimatedBuilder( - animation: animationController, - builder: (context, child) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: CustomGuage( - size: (248 * screenHeight) / 480, - low: minRPM, - high: maxRPM, - mainValue: animationController.value, - label: "rpm", - zeroTickLabel: minRPM.toInt().toString(), - maxTickLabel: maxRPM.toInt().toString(), - inPrimaryColor: guageColor?.inPrimary, - outPrimaryColor: guageColor?.outPrimary, - secondaryColor: guageColor?.secondary, - ), - ); - }); - } -} diff --git a/lib/screen/widgets/guages/speed_guage_animation_wrapper.dart b/lib/screen/widgets/guages/speed_guage_animation_wrapper.dart deleted file mode 100644 index 8704fcd..0000000 --- a/lib/screen/widgets/guages/speed_guage_animation_wrapper.dart +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:flutter_cluster_dashboard/screen/widgets/guages/guage_props.dart'; -import 'package:flutter_cluster_dashboard/screen/widgets/guages/guage_widget.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_model.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_provider.dart'; - -class SpeedGauge extends HookConsumerWidget { - final double screenHeight; - final GuageColors? guageColor; - const SpeedGauge({Key? key, required this.screenHeight, this.guageColor}) - : super(key: key); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final VehicleSignal vehicle = ref.watch(vehicleSignalProvider); - - const double minSpeed = 0; - const double maxSpeed = 240; - const Duration sweepDuration = Duration(milliseconds: 200); - double speedScaling = - (vehicle.vehicleDistanceUnit == "mi") ? 0.621504 : 1.0; - - final animationController = useAnimationController( - lowerBound: minSpeed, - upperBound: maxSpeed, - )..animateTo(speedScaling * (vehicle.speed), - duration: sweepDuration, curve: Curves.linearToEaseOut); - - return AnimatedBuilder( - animation: animationController, - builder: (context, child) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: CustomGuage( - size: (248 * screenHeight) / 480, - low: minSpeed, - high: maxSpeed, - mainValue: animationController.value, - label: (vehicle.vehicleDistanceUnit == "mi") ? "mph" : "Km/h", - zeroTickLabel: minSpeed.toInt().toString(), - maxTickLabel: maxSpeed.toInt().toString(), - inPrimaryColor: guageColor?.inPrimary, - outPrimaryColor: guageColor?.outPrimary, - secondaryColor: guageColor?.secondary, - ), - ); - }); - } -} - -final guageColorProvider = Provider.family((ref, mode) { - switch (mode) { - case "normal": - return GuageColors(inPrimary: Colors.red); - case "sports": - return GuageColors(inPrimary: Colors.blue); - case "eco": - return GuageColors(inPrimary: Colors.green); - default: - return GuageColors(); - } -}); diff --git a/lib/screen/widgets/left_bar.dart b/lib/screen/widgets/left_bar.dart index 3192c28..ea877a5 100644 --- a/lib/screen/widgets/left_bar.dart +++ b/lib/screen/widgets/left_bar.dart @@ -4,8 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:flutter_cluster_dashboard/screen/paints/arc_painter.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_model.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_provider.dart'; +import 'package:flutter_cluster_dashboard/vehicle-signals/vehicle_status_provider.dart'; class LeftArc extends HookConsumerWidget { final double screenHeight; @@ -14,11 +13,11 @@ class LeftArc extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final VehicleSignal vehicle = ref.watch(vehicleSignalProvider); + final double coolantTemp = ref.watch(vehicleStatusProvider.select((p) => p.coolantTemp)); final animationController = useAnimationController( lowerBound: 0, upperBound: 100, - )..animateTo(vehicle.coolantTemp, + )..animateTo(coolantTemp, duration: const Duration(milliseconds: 1000)); return AnimatedBuilder( diff --git a/lib/screen/widgets/right_bar.dart b/lib/screen/widgets/right_bar.dart index e5ed44d..a3d9ef4 100644 --- a/lib/screen/widgets/right_bar.dart +++ b/lib/screen/widgets/right_bar.dart @@ -4,8 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:flutter_cluster_dashboard/screen/paints/arc_painter.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_model.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_provider.dart'; +import 'package:flutter_cluster_dashboard/vehicle-signals/vehicle_status_provider.dart'; class RightArc extends HookConsumerWidget { final double screenHeight; @@ -13,11 +12,11 @@ class RightArc extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final VehicleSignal vehicle = ref.watch(vehicleSignalProvider); + final double fuelLevel = ref.watch(vehicleStatusProvider.select((p) => p.fuelLevel)); final animationController = useAnimationController( lowerBound: 0, upperBound: 100, - )..animateTo(vehicle.fuelLevel, + )..animateTo(fuelLevel, duration: const Duration(milliseconds: 500)); return AnimatedBuilder( diff --git a/lib/screen/widgets/signals.dart b/lib/screen/widgets/signals.dart index dbdffb5..befaf7b 100644 --- a/lib/screen/widgets/signals.dart +++ b/lib/screen/widgets/signals.dart @@ -1,61 +1,70 @@ // SPDX-License-Identifier: Apache-2.0 import 'package:flutter/material.dart'; -import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_model.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_cluster_dashboard/vehicle-signals/vehicle_status_provider.dart'; -class Signals extends StatelessWidget { - final VehicleSignal vehicle; +class Signals extends ConsumerWidget { final double screenHeight; static Color idleColor = Colors.grey.shade600; const Signals({ Key? key, - required this.screenHeight, - required this.vehicle, + required this.screenHeight }) : super(key: key); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { + final bool isLowBeam = ref.watch(vehicleStatusProvider.select((p) => p.isLowBeam)); + final bool isHighBeam = ref.watch(vehicleStatusProvider.select((p) => p.isHighBeam)); + final bool isHazardLightOn = ref.watch(vehicleStatusProvider.select((p) => p.isHazardLightOn)); + final bool isParkingOn = ref.watch(vehicleStatusProvider.select((p) => p.isParkingOn)); + final bool isBatteryCharging = ref.watch(vehicleStatusProvider.select((p) => p.isBatteryCharging)); + final bool isMILon = ref.watch(vehicleStatusProvider.select((p) => p.isMILon)); + final bool isSteeringLaneWarning = ref.watch(vehicleStatusProvider.select((p) => p.isSteeringLaneWarning)); + final bool isSteeringCruiseEnable = ref.watch(vehicleStatusProvider.select((p) => p.isSteeringCruiseEnable)); + final bool isSteeringCruiseSet = ref.watch(vehicleStatusProvider.select((p) => p.isSteeringCruiseSet)); + return Wrap( spacing: 14, runAlignment: WrapAlignment.spaceBetween, alignment: WrapAlignment.spaceEvenly, children: [ - (vehicle.isLowBeam) + isLowBeam ? Image.asset("images/low-beam.png", color: Colors.green, width: (20 * screenHeight) / 480) - : (vehicle.isHighBeam) + : isHighBeam ? Image.asset("images/high-beam.png", color: Colors.green, width: (20 * screenHeight) / 480) : Image.asset("images/high-beam.png", color: idleColor, width: (20 * screenHeight) / 480), Image.asset("images/hazard.png", - color: (vehicle.isHazardLightOn) ? Colors.red : idleColor, + color: isHazardLightOn ? Colors.red : idleColor, width: (20 * screenHeight) / 480), Image.asset("images/parking.png", - color: (vehicle.isParkingOn) ? Colors.green : idleColor, + color: isParkingOn ? Colors.green : idleColor, width: (20 * screenHeight) / 480), Image.asset("images/battery.png", - color: (vehicle.isBatteryCharging) ? Colors.green : Colors.red, + color: isBatteryCharging ? Colors.green : Colors.red, width: (20 * screenHeight) / 480), Image.asset("images/malfunction.png", - color: (vehicle.isMILon) ? Colors.red : idleColor, + color: isMILon ? Colors.red : idleColor, width: (20 * screenHeight) / 480), // Image.asset("images/openDoor.png", - color: (vehicle.isMILon) ? Colors.white : idleColor, + color: isMILon ? Colors.white : idleColor, width: (20 * screenHeight) / 480), Image.asset("images/seatBelt.png", - color: (vehicle.isMILon) ? Colors.white : idleColor, + color: isMILon ? Colors.white : idleColor, width: (20 * screenHeight) / 480), // Image.asset("images/lane.png", - color: (vehicle.isSteeringLaneWarning) ? Colors.white : idleColor, + color: (isSteeringLaneWarning) ? Colors.white : idleColor, width: (25 * screenHeight) / 480), Image.asset("images/cruise.png", - color: (vehicle.isSteeringCruiseEnable) - ? (vehicle.isSteeringCruiseSet) + color: (isSteeringCruiseEnable) + ? (isSteeringCruiseSet) ? Colors.green : Colors.orange : idleColor, -- cgit 1.2.3-korg