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>
56 lines
1.6 KiB
Dart
56 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
||
enum AppThemeVariant { redDark, redLight, greenDark, greenLight }
|
||
|
||
const _themeKey = 'themeVariant';
|
||
|
||
/// Colour scheme (red/green) × brightness (dark/light), persisted.
|
||
class ThemeNotifier extends StateNotifier<AppThemeVariant> {
|
||
ThemeNotifier() : super(AppThemeVariant.redDark) {
|
||
_load();
|
||
}
|
||
|
||
Future<void> _load() async {
|
||
try {
|
||
final prefs = await SharedPreferences.getInstance();
|
||
final saved = prefs.getString(_themeKey);
|
||
for (final v in AppThemeVariant.values) {
|
||
if (v.name == saved && mounted) state = v;
|
||
}
|
||
} catch (_) {
|
||
// Keep the default if preferences can't be read.
|
||
}
|
||
}
|
||
|
||
void set(AppThemeVariant v) {
|
||
state = v;
|
||
SharedPreferences.getInstance()
|
||
.then((prefs) => prefs.setString(_themeKey, v.name))
|
||
.catchError((Object _) => false);
|
||
}
|
||
}
|
||
|
||
final themeProvider =
|
||
StateNotifierProvider<ThemeNotifier, AppThemeVariant>(
|
||
(ref) => ThemeNotifier(),
|
||
);
|
||
|
||
/// Returns the accent color for the current theme variant.
|
||
extension AppThemeVariantX on AppThemeVariant {
|
||
Color get accentColor {
|
||
switch (this) {
|
||
case AppThemeVariant.redDark:
|
||
case AppThemeVariant.redLight:
|
||
return const Color(0xFFFF4444);
|
||
case AppThemeVariant.greenDark:
|
||
case AppThemeVariant.greenLight:
|
||
return const Color(0xFF00E676);
|
||
}
|
||
}
|
||
|
||
bool get isDark =>
|
||
this == AppThemeVariant.redDark || this == AppThemeVariant.greenDark;
|
||
}
|