summaryrefslogtreecommitdiffstats
path: root/lib/screen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/screen')
-rw-r--r--lib/screen/home.dart128
-rw-r--r--lib/screen/paints/gauge_paint.dart (renamed from lib/screen/paints/guage_paint.dart)16
-rw-r--r--lib/screen/widgets/gauges/gauge_props.dart (renamed from lib/screen/widgets/guages/guage_props.dart)12
-rw-r--r--lib/screen/widgets/gauges/gauge_widget.dart (renamed from lib/screen/widgets/guages/guage_widget.dart)20
-rw-r--r--lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart (renamed from lib/screen/widgets/guages/rpm_guage_animation_wrapper.dart)23
-rw-r--r--lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart (renamed from lib/screen/widgets/guages/speed_guage_animation_wrapper.dart)39
-rw-r--r--lib/screen/widgets/left_bar.dart7
-rw-r--r--lib/screen/widgets/right_bar.dart7
-rw-r--r--lib/screen/widgets/signals.dart43
9 files changed, 154 insertions, 141 deletions
diff --git a/lib/screen/home.dart b/lib/screen/home.dart
index 3bd47a8..f154550 100644
--- a/lib/screen/home.dart
+++ b/lib/screen/home.dart
@@ -2,29 +2,44 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
-import 'package:flutter_cluster_dashboard/map/navigationHome.dart';
import 'package:flutter_cluster_dashboard/provider.dart';
-import 'package:flutter_cluster_dashboard/screen/widgets/guages/guage_props.dart';
+import 'package:flutter_cluster_dashboard/screen/widgets/gauges/gauge_props.dart';
import 'package:flutter_cluster_dashboard/screen/paints/bottombar_paint.dart';
import 'package:flutter_cluster_dashboard/screen/paints/topbar_paint.dart';
-import 'package:flutter_cluster_dashboard/screen/widgets/guages/rpm_guage_animation_wrapper.dart';
+import 'package:flutter_cluster_dashboard/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/left_bar.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/performance_mode.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/right_bar.dart';
-import 'package:flutter_cluster_dashboard/screen/widgets/guages/speed_guage_animation_wrapper.dart';
+import 'package:flutter_cluster_dashboard/screen/widgets/gauges/speed_gauge_animation_wrapper.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/signals.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/turn_signal.dart';
-import 'package:flutter_cluster_dashboard/vehicle_signal/vehicle_signal_provider.dart';
-import 'package:flutter_cluster_dashboard/cluster_config.dart';
+import 'package:flutter_cluster_dashboard/vehicle-signals/vss_client.dart';
+import 'package:flutter_cluster_dashboard/vehicle-signals/vss_provider.dart';
+import 'package:flutter_cluster_dashboard/vehicle-signals/vehicle_status_provider.dart';
import 'package:intl/intl.dart';
-class Home extends ConsumerWidget {
+class Home extends ConsumerStatefulWidget {
const Home({Key? key}) : super(key: key);
- GuageColors? getGuageColor(String mode) {
+
+ @override
+ _HomeState createState() => _HomeState();
+}
+
+class _HomeState extends ConsumerState<Home> {
+ late VssClient vss;
+
+ initState() {
+ vss = ref.read(vssClientProvider);
+ vss.run();
+
+ super.initState();
+ }
+
+ GaugeColors? getGaugeColor(String mode) {
return (mode == "economy")
- ? GuageProps.ecoModeColor
+ ? GaugeProps.ecoModeColor
: (mode == "sport")
- ? GuageProps.sportModeColor
+ ? GaugeProps.sportModeColor
: null;
}
@@ -46,9 +61,12 @@ class Home extends ConsumerWidget {
}
@override
- Widget build(BuildContext context, WidgetRef ref) {
- final clusterConfig = ref.read(clusterConfigStateprovider);
- final vehicle = ref.watch(vehicleSignalProvider);
+ Widget build(BuildContext context) {
+ final bool isLeftIndicator = ref.watch(vehicleStatusProvider.select((p) => p.isLeftIndicator));
+ final bool isRightIndicator = ref.watch(vehicleStatusProvider.select((p) => p.isRightIndicator));
+ final String performanceMode = ref.watch(vehicleStatusProvider.select((p) => p.performanceMode));
+ final String selectedGear = ref.watch(vehicleStatusProvider.select((p) => p.selectedGear));
+ final double ambientAirTemp = ref.watch(vehicleStatusProvider.select((p) => p.ambientAirTemp));
final clock = ref.watch(clockProvider);
final windowHeight = MediaQuery.of(context).size.height;
final windowWidth = MediaQuery.of(context).size.width;
@@ -68,7 +86,7 @@ class Home extends ConsumerWidget {
}
return Scaffold(
- backgroundColor: GuageProps.bgColor,
+ backgroundColor: GaugeProps.bgColor,
body: SafeArea(
child: Center(
child: Center(
@@ -87,8 +105,8 @@ class Home extends ConsumerWidget {
children: [
TurnSignal(
screenHeight: screenHeight,
- isLefton: vehicle.isLeftIndicator,
- isRighton: vehicle.isRightIndicator,
+ isLefton: isLeftIndicator,
+ isRighton: isRightIndicator,
),
Flex(
direction: Axis.horizontal,
@@ -128,7 +146,7 @@ class Home extends ConsumerWidget {
SizedBox(
width: (30 * screenHeight) / 480),
Text(
- "${vehicle.ambientAirTemp} ${"\u00B0"}C",
+ "${ambientAirTemp} ${"\u00B0"}C",
style: TextStyle(
color: const Color.fromARGB(
255, 184, 183, 183),
@@ -216,7 +234,7 @@ class Home extends ConsumerWidget {
child: PerformanceMode(
size: Size((90 * screenHeight) / 480,
(20 * screenHeight) / 480),
- mode: vehicle.performanceMode),
+ mode: performanceMode),
),
// logo
Flexible(
@@ -224,25 +242,18 @@ class Home extends ConsumerWidget {
fit: FlexFit.tight,
child: SizedBox(
width: (330 * screenHeight) / 720,
- child: (clusterConfig
- .enableNavigation &&
- vehicle.isSteeringInfo)
- ? const NavigationHome()
- : Padding(
- padding: EdgeInsets.symmetric(
- vertical:
- (36.0 * screenHeight) /
- 720,
- horizontal:
- (48.0 * screenHeight) /
- 720),
- child: Image.asset(
- "images/logo_agl.png",
- width:
- (90 * screenHeight) / 480,
- color: Colors.grey.shade600,
- ),
- ),
+ child: Padding(
+ padding: EdgeInsets.symmetric(
+ vertical:
+ (36.0 * screenHeight) / 720,
+ horizontal:
+ (48.0 * screenHeight) / 720),
+ child: Image.asset(
+ "images/logo_agl.png",
+ width: (90 * screenHeight) / 480,
+ color: Colors.grey.shade600,
+ ),
+ ),
),
),
const Flexible(
@@ -265,14 +276,11 @@ class Home extends ConsumerWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
- Signals(
- screenHeight: screenHeight,
- vehicle: vehicle,
- ),
+ Signals(screenHeight: screenHeight),
],
),
),
- // guages
+ // gauges
Padding(
padding: EdgeInsets.fromLTRB(
calcPadding(70, screenHeight),
@@ -283,17 +291,17 @@ class Home extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
- // Speed Guage
+ // Speed Gauge
SpeedGauge(
screenHeight: screenHeight,
- guageColor:
- getGuageColor(vehicle.performanceMode),
+ gaugeColor:
+ getGaugeColor(performanceMode),
),
- //RPM Guage
+ //RPM Gauge
RPMGauge(
screenHeight: screenHeight,
- guageColor:
- getGuageColor(vehicle.performanceMode),
+ gaugeColor:
+ getGaugeColor(performanceMode),
),
],
),
@@ -314,33 +322,33 @@ class Home extends ConsumerWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
- (vehicle.selectedGear == Gear.parking)
+ (selectedGear == Gear.parking)
? Text("P",
- style: GuageProps.activeGearIconStyle(
+ style: GaugeProps.activeGearIconStyle(
screenHeight))
: Text("P",
- style: GuageProps.gearIconStyle(
+ style: GaugeProps.gearIconStyle(
screenHeight)),
- (vehicle.selectedGear == Gear.reverse)
+ (selectedGear == Gear.reverse)
? Text("R",
- style: GuageProps.activeGearIconStyle(
+ style: GaugeProps.activeGearIconStyle(
screenHeight))
: Text("R",
- style: GuageProps.gearIconStyle(
+ style: GaugeProps.gearIconStyle(
screenHeight)),
- (vehicle.selectedGear == Gear.neutral)
+ (selectedGear == Gear.neutral)
? Text("N",
- style: GuageProps.activeGearIconStyle(
+ style: GaugeProps.activeGearIconStyle(
screenHeight))
: Text("N",
- style: GuageProps.gearIconStyle(
+ style: GaugeProps.gearIconStyle(
screenHeight)),
- (vehicle.selectedGear == Gear.drive)
+ (selectedGear == Gear.drive)
? Text("D",
- style: GuageProps.activeGearIconStyle(
+ style: GaugeProps.activeGearIconStyle(
screenHeight))
: Text("D",
- style: GuageProps.gearIconStyle(
+ style: GaugeProps.gearIconStyle(
screenHeight)),
]),
),
diff --git a/lib/screen/paints/guage_paint.dart b/lib/screen/paints/gauge_paint.dart
index 22f7544..bae265c 100644
--- a/lib/screen/paints/guage_paint.dart
+++ b/lib/screen/paints/gauge_paint.dart
@@ -3,15 +3,15 @@
import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:ui' as ui;
-import 'package:flutter_cluster_dashboard/screen/widgets/guages/guage_props.dart';
+import 'package:flutter_cluster_dashboard/screen/widgets/gauges/gauge_props.dart';
-class GuagePainter extends CustomPainter {
+class GaugePainter extends CustomPainter {
final double low, high;
double currentSpeed;
final Color? outPrimaryColor;
final Color? inPrimaryColor;
final Color? secondaryColor;
- GuagePainter({
+ GaugePainter({
required this.low,
required this.high,
required this.currentSpeed,
@@ -25,7 +25,7 @@ class GuagePainter extends CustomPainter {
double radius = min(size.width / 2, size.height / 2);
double radius1 = radius - ((20 / 200) * (radius));
double speedAngle =
- GuageProps.degToRad((GuageProps.majorAngle / high) * currentSpeed);
+ GaugeProps.degToRad((GaugeProps.majorAngle / high) * currentSpeed);
final zeroTickPaint = Paint()
..strokeWidth = ((7 / 200) * (radius))
@@ -89,8 +89,8 @@ class GuagePainter extends CustomPainter {
[Colors.black, const Color.fromARGB(255, 142, 35, 39)], [0.65, 0.9]);
for (double i = 0; i < 13; i++) {
- double startAngle = GuageProps.degToRad(i * 20);
- double gapAngle = GuageProps.degToRad(19);
+ double startAngle = GaugeProps.degToRad(i * 20);
+ double gapAngle = GaugeProps.degToRad(19);
var outerPath = Path();
outerPath.addArc(Rect.fromCircle(center: center, radius: radius),
@@ -132,8 +132,8 @@ class GuagePainter extends CustomPainter {
zeroTickPaint);
canvas.drawLine(
center,
- Offset(center.dx + (radius) * cos(GuageProps.majorAngleRad),
- center.dy + (radius) * sin(GuageProps.majorAngleRad)),
+ Offset(center.dx + (radius) * cos(GaugeProps.majorAngleRad),
+ center.dy + (radius) * sin(GaugeProps.majorAngleRad)),
maxTickPaint);
}
diff --git a/lib/screen/widgets/guages/guage_props.dart b/lib/screen/widgets/gauges/gauge_props.dart
index bb56a31..51dba51 100644
--- a/lib/screen/widgets/guages/guage_props.dart
+++ b/lib/screen/widgets/gauges/gauge_props.dart
@@ -3,17 +3,17 @@
import 'dart:math';
import 'package:flutter/material.dart';
-class GuageProps {
- static GuageColors normalModeColor = GuageColors(
+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 GuageColors sportModeColor = GuageColors(
+ static GaugeColors sportModeColor = GaugeColors(
inPrimary: Colors.deepPurple,
outPrimary: Colors.blue,
secondary: const Color.fromARGB(214, 202, 202, 202));
- static GuageColors ecoModeColor = GuageColors(
+ 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));
@@ -40,9 +40,9 @@ class GuageProps {
}
}
-class GuageColors {
+class GaugeColors {
Color? inPrimary;
Color? outPrimary;
Color? secondary;
- GuageColors({this.inPrimary, this.outPrimary, this.secondary});
+ GaugeColors({this.inPrimary, this.outPrimary, this.secondary});
}
diff --git a/lib/screen/widgets/guages/guage_widget.dart b/lib/screen/widgets/gauges/gauge_widget.dart
index fa43958..c302953 100644
--- a/lib/screen/widgets/guages/guage_widget.dart
+++ b/lib/screen/widgets/gauges/gauge_widget.dart
@@ -2,11 +2,11 @@
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';
+import 'package:flutter_cluster_dashboard/screen/paints/gauge_paint.dart';
+import 'package:flutter_cluster_dashboard/screen/widgets/gauges/gauge_props.dart';
-class CustomGuage extends StatelessWidget {
- const CustomGuage({
+class CustomGauge extends StatelessWidget {
+ const CustomGauge({
Key? key,
required this.mainValue,
required this.low,
@@ -59,14 +59,14 @@ class CustomGuage extends StatelessWidget {
child: Stack(
alignment: Alignment.topCenter,
children: [
- // Guage painter
+ // Gauge painter
Positioned(
top: 0,
child: Transform.rotate(
- angle: (pi / 2) + (GuageProps.minorAngle * (pi / 360.0)),
+ angle: (pi / 2) + (GaugeProps.minorAngle * (pi / 360.0)),
child: CustomPaint(
size: Size(size ?? 400, size ?? 400),
- painter: GuagePainter(
+ painter: GaugePainter(
low: low,
high: high,
currentSpeed: mainValue,
@@ -77,17 +77,17 @@ class CustomGuage extends StatelessWidget {
),
),
),
- // Guage Label
+ // Gauge Label
Positioned(
top: distLabelTop ?? ((100 / 400) * (size ?? 400)),
child: Text(label, style: labelTextStyle),
),
- // Guage Main Value
+ // Gauge Main Value
Positioned(
top: distMainTop ?? ((150 / 400) * (size ?? 400)),
child: Text("${mainValue.toInt()}", style: mainValueTextStyle),
),
- // Guage Ticks value
+ // Gauge Ticks value
Positioned(
bottom: distTicksBottom ?? ((80 / 400) * (size ?? 400)),
child: Row(
diff --git a/lib/screen/widgets/guages/rpm_guage_animation_wrapper.dart b/lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart
index 95403dd..fa76bd8 100644
--- a/lib/screen/widgets/guages/rpm_guage_animation_wrapper.dart
+++ b/lib/screen/widgets/gauges/rpm_gauge_animation_wrapper.dart
@@ -4,20 +4,19 @@ 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';
+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 GuageColors? guageColor;
- const RPMGauge({Key? key, required this.screenHeight, this.guageColor})
+ final GaugeColors? gaugeColor;
+ const RPMGauge({Key? key, required this.screenHeight, this.gaugeColor})
: super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
- final VehicleSignal vehicle = ref.watch(vehicleSignalProvider);
+ final double rpm = ref.watch(vehicleStatusProvider.select((p) => p.rpm));
const double minRPM = 0;
const double maxRPM = 8000;
@@ -26,14 +25,14 @@ class RPMGauge extends HookConsumerWidget {
final animationController = useAnimationController(
lowerBound: minRPM,
upperBound: maxRPM,
- )..animateTo(vehicle.rpm,
+ )..animateTo(rpm,
duration: sweepDuration, curve: Curves.linearToEaseOut);
return AnimatedBuilder(
animation: animationController,
builder: (context, child) {
return Padding(
padding: const EdgeInsets.all(8.0),
- child: CustomGuage(
+ child: CustomGauge(
size: (248 * screenHeight) / 480,
low: minRPM,
high: maxRPM,
@@ -41,9 +40,9 @@ class RPMGauge extends HookConsumerWidget {
label: "rpm",
zeroTickLabel: minRPM.toInt().toString(),
maxTickLabel: maxRPM.toInt().toString(),
- inPrimaryColor: guageColor?.inPrimary,
- outPrimaryColor: guageColor?.outPrimary,
- secondaryColor: guageColor?.secondary,
+ inPrimaryColor: gaugeColor?.inPrimary,
+ outPrimaryColor: gaugeColor?.outPrimary,
+ secondaryColor: gaugeColor?.secondary,
),
);
});
diff --git a/lib/screen/widgets/guages/speed_guage_animation_wrapper.dart b/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart
index 8704fcd..dfa4277 100644
--- a/lib/screen/widgets/guages/speed_guage_animation_wrapper.dart
+++ b/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart
@@ -3,31 +3,30 @@
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';
+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 GuageColors? guageColor;
- const SpeedGauge({Key? key, required this.screenHeight, this.guageColor})
+ final GaugeColors? gaugeColor;
+ const SpeedGauge({Key? key, required this.screenHeight, this.gaugeColor})
: super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
- final VehicleSignal vehicle = ref.watch(vehicleSignalProvider);
+ 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 =
- (vehicle.vehicleDistanceUnit == "mi") ? 0.621504 : 1.0;
+ double speedScaling = (units == "mi") ? 0.621504 : 1.0;
final animationController = useAnimationController(
lowerBound: minSpeed,
upperBound: maxSpeed,
- )..animateTo(speedScaling * (vehicle.speed),
+ )..animateTo(speedScaling * speed,
duration: sweepDuration, curve: Curves.linearToEaseOut);
return AnimatedBuilder(
@@ -35,32 +34,32 @@ class SpeedGauge extends HookConsumerWidget {
builder: (context, child) {
return Padding(
padding: const EdgeInsets.all(8.0),
- child: CustomGuage(
+ child: CustomGauge(
size: (248 * screenHeight) / 480,
low: minSpeed,
high: maxSpeed,
mainValue: animationController.value,
- label: (vehicle.vehicleDistanceUnit == "mi") ? "mph" : "Km/h",
+ label: (units == "mi") ? "mph" : "Km/h",
zeroTickLabel: minSpeed.toInt().toString(),
maxTickLabel: maxSpeed.toInt().toString(),
- inPrimaryColor: guageColor?.inPrimary,
- outPrimaryColor: guageColor?.outPrimary,
- secondaryColor: guageColor?.secondary,
+ inPrimaryColor: gaugeColor?.inPrimary,
+ outPrimaryColor: gaugeColor?.outPrimary,
+ secondaryColor: gaugeColor?.secondary,
),
);
});
}
}
-final guageColorProvider = Provider.family<GuageColors, String>((ref, mode) {
+final gaugeColorProvider = Provider.family<GaugeColors, String>((ref, mode) {
switch (mode) {
case "normal":
- return GuageColors(inPrimary: Colors.red);
+ return GaugeColors(inPrimary: Colors.red);
case "sports":
- return GuageColors(inPrimary: Colors.blue);
+ return GaugeColors(inPrimary: Colors.blue);
case "eco":
- return GuageColors(inPrimary: Colors.green);
+ return GaugeColors(inPrimary: Colors.green);
default:
- return GuageColors();
+ return GaugeColors();
}
});
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,