diff options
Diffstat (limited to 'lib/screen/widgets')
-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.dart | 7 | ||||
-rw-r--r-- | lib/screen/widgets/right_bar.dart | 7 | ||||
-rw-r--r-- | lib/screen/widgets/signals.dart | 43 |
7 files changed, 78 insertions, 73 deletions
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,
|