Files
smart-serow/pi/ui/lib/screens/dashboard_screen.dart

144 lines
4.2 KiB
Dart
Raw Normal View History

2026-01-25 18:47:35 +09:00
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
2026-01-25 19:23:03 +09:00
import '../services/pi_io.dart';
import '../theme/app_theme.dart';
import '../widgets/navigator_widget.dart';
2026-01-25 18:47:35 +09:00
import '../widgets/stat_box.dart';
2026-01-26 15:47:59 +09:00
import '../widgets/stat_box_main.dart';
import '../widgets/system_bar.dart';
2026-01-25 18:47:35 +09:00
// test service for triggers
import '../services/test_flipflop_service.dart';
2026-01-25 19:23:03 +09:00
/// Main dashboard - displays Pi vitals and placeholder stats
2026-01-25 18:47:35 +09:00
class DashboardScreen extends StatefulWidget {
const DashboardScreen({super.key});
@override
State<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
final _random = Random();
final _navigatorKey = GlobalKey<NavigatorWidgetState>();
2026-01-25 18:47:35 +09:00
Timer? _timer;
2026-01-25 19:23:03 +09:00
double? _piTemp;
2026-01-25 18:47:35 +09:00
int _rpm = 0;
double _voltage = 12.6;
2026-01-26 15:47:59 +09:00
int _engineTemp = 25;
// Placeholder values for system bar
int? _gpsSatellites;
int? _lteSignal;
2026-01-25 18:47:35 +09:00
@override
void initState() {
super.initState();
2026-01-25 19:23:03 +09:00
// Update values periodically
2026-01-25 18:47:35 +09:00
_timer = Timer.periodic(const Duration(milliseconds: 500), (_) {
setState(() {
2026-01-25 19:23:03 +09:00
// Pi temp - sync read from cache, async refresh happens in background
_piTemp = PiIO.instance.getTemperature();
// Placeholder random data - will be replaced with real sensors
2026-01-25 18:47:35 +09:00
_rpm = 1000 + _random.nextInt(8000);
_voltage = 11.5 + _random.nextDouble() * 2;
2026-01-26 15:47:59 +09:00
_engineTemp = 20 + _random.nextInt(60);
// Placeholder: GPS satellites (null = disconnected, 0 = no fix, 3-12 = typical)
_gpsSatellites = _random.nextBool() ? _random.nextInt(12) : null;
// Placeholder: LTE signal (null = disconnected, 0-4 = signal bars)
_lteSignal = _random.nextBool() ? _random.nextInt(5) : null;
2026-01-25 18:47:35 +09:00
});
});
// DEBUG: flip-flop theme + navigator every 2s
TestFlipFlopService.instance.start(navigatorKey: _navigatorKey);
2026-01-25 18:47:35 +09:00
}
@override
void dispose() {
_timer?.cancel();
TestFlipFlopService.instance.stop();
2026-01-25 18:47:35 +09:00
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = AppTheme.of(context);
2026-01-25 18:47:35 +09:00
return Scaffold(
backgroundColor: theme.background,
2026-01-25 18:47:35 +09:00
body: Padding(
2026-01-26 15:47:59 +09:00
padding: const EdgeInsets.all(16),
child: Row(
2026-01-25 18:47:35 +09:00
children: [
// Left side: All dashboard widgets (flex: 2)
Expanded(
flex: 2,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
2026-01-26 15:47:59 +09:00
// System status bar
SystemBar(
gpsSatellites: _gpsSatellites,
lteSignal: _lteSignal,
piTemp: _piTemp,
voltage: _voltage,
2026-01-25 18:47:35 +09:00
),
2026-01-26 15:47:59 +09:00
const SizedBox(height: 10),
2026-01-26 15:47:59 +09:00
// Main content area - big stat boxes
Expanded(
2026-01-26 15:47:59 +09:00
flex: 8,
child: Row(
children: [
// Speed - placeholder, will come from GPS
StatBoxMain(
value: _rpm.toString(),
label: 'RPM',
),
// Add second StatBoxMain here for 2-up layout:
// StatBoxMain(value: '4500', unit: 'rpm', label: 'TACH'),
],
),
2026-01-25 18:47:35 +09:00
),
// Bottom stats row
2026-01-26 15:47:59 +09:00
Expanded(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
StatBox(value: _rpm.toString(), label: 'RPM'),
StatBox(value: '$_engineTemp', unit: '°C', label: 'ENG'),
const StatBox(value: '', label: 'GEAR'),
],
),
),
],
),
2026-01-25 18:47:35 +09:00
),
const SizedBox(width: 32),
2026-01-25 18:47:35 +09:00
// Right side: Image display (flex: 1)
2026-01-25 18:47:35 +09:00
Expanded(
flex: 1,
2026-01-25 18:47:35 +09:00
child: Center(
child: NavigatorWidget(key: _navigatorKey),
2026-01-25 18:47:35 +09:00
),
),
],
),
),
);
}
}