hondavert-dev/lib/ui/screens/dashboard/widgets/dashboard_common.dart
metatroncubeswdev e4bcfb57a6 Meet Requrements.pdf: selectable dashboard, units, list/graph, light mode, playback
Dashboard
- Selectable main sensor (gauge) + sub sensor, 10 selectable values
  (landscape 5 left + 5 right, portrait 2x5 on one screen) and 4
  selectable flags; long-press to change; persisted.
- Flags: the requirement examples (MIL, FAN Out, VTEC Out, Knock, WBO /
  IAT / CLT Error - errors derived from the stored DTC bits) plus the
  other S300 status bits (cuts, launch, closed loop, VTP, AC, brake).
- Record button moved to the app bar; debug screen moved to Settings.

Sensor list: 1 column on phone portrait, 2 on tablet/landscape; name,
unit, min/max, segmented bar and value.
Graph: auto-scaled Y, window max/min, current value, seconds axis and a
touch cursor; RPM/MAP/TPS/ECT by default.
Units: km/h|mph, degC|degF, kPa|bar|psi (display only), persisted.
Light/dark: palette is a ThemeExtension used by every screen; theme
persisted. SafeArea keeps content off the side navigation bar.
Datalog playback now drives the dashboard, list, graph and DTC screen,
with the playback bar on the main screen and seek updating the displays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 23:24:28 -04:00

96 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/models/sensor_defs.dart';
import '../../../../core/models/units.dart';
import '../../../../core/protocol/sensor_state.dart';
import '../../../../core/providers/settings_provider.dart';
import '../../../theme/app_colors.dart';
import '../dashboard_slots_provider.dart';
import 'analog_gauge.dart';
import 'sensor_picker_sheet.dart';
/// Gauge for the selectable main sensor with the sub sensor as a second
/// line. Long-press to change either.
class MainGauge extends ConsumerWidget {
final SensorState state;
const MainGauge({super.key, required this.state});
@override
Widget build(BuildContext context, WidgetRef ref) {
final c = AppColors.of(context);
final config = ref.watch(dashboardConfigProvider);
final units = ref.watch(unitPrefsProvider);
final main = sensorView(config.main, units);
final sub = sensorView(config.sub, units);
final mainBase = sensorValue(state, config.main);
final subBase = sensorValue(state, config.sub);
return GestureDetector(
onLongPress: () => _editGauge(context, ref),
child: AnalogGauge(
value: main.convert(mainBase),
minValue: main.min,
maxValue: main.max,
label: main.name.toUpperCase(),
unit: main.unit,
valueText: main.format(mainBase),
subText: '${sub.format(subBase)} ${sub.unit}'.trim(),
accentColor: c.accent,
foreground: c.onSurface,
muted: c.onSurfaceMuted,
track: c.track,
background: c.background,
),
);
}
Future<void> _editGauge(BuildContext context, WidgetRef ref) async {
final which = await showPickerSheet(
context,
title: 'GAUGE',
currentId: '',
items: const [
PickerItem('main', 'Change main sensor'),
PickerItem('sub', 'Change sub sensor'),
],
);
if (which == null || !context.mounted) return;
final config = ref.read(dashboardConfigProvider);
final id = await pickSensor(
context,
title: which == 'main' ? 'MAIN SENSOR' : 'SUB SENSOR',
currentId: which == 'main' ? config.main : config.sub,
units: ref.read(unitPrefsProvider),
);
if (id == null) return;
final n = ref.read(dashboardConfigProvider.notifier);
which == 'main' ? n.setMain(id) : n.setSub(id);
}
}
Future<void> editDashboardValue(
BuildContext context, WidgetRef ref, int index) async {
final id = await pickSensor(
context,
title: 'SELECT SENSOR',
currentId: ref.read(dashboardConfigProvider).values[index],
units: ref.read(unitPrefsProvider),
);
if (id != null) {
ref.read(dashboardConfigProvider.notifier).setValue(index, id);
}
}
Future<void> editDashboardFlag(
BuildContext context, WidgetRef ref, int index) async {
final id = await pickFlag(
context,
currentId: ref.read(dashboardConfigProvider).flags[index],
);
if (id != null) {
ref.read(dashboardConfigProvider.notifier).setFlag(index, id);
}
}