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

156 lines
4.7 KiB
Dart
Raw Normal View History

2026-01-25 18:47:35 +09:00
import 'dart:async';
2026-01-25 23:13:30 +09:00
import 'dart:io';
2026-01-25 18:47:35 +09:00
import 'dart:math';
import 'package:flutter/material.dart';
2026-01-25 23:13:30 +09:00
import '../services/config_service.dart';
2026-01-25 19:23:03 +09:00
import '../services/pi_io.dart';
2026-01-25 18:47:35 +09:00
import '../widgets/stat_box.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();
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;
int _temp = 25;
@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;
_temp = 20 + _random.nextInt(60);
});
});
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
2026-01-25 23:13:30 +09:00
/// Build navigator image from filesystem
Widget _buildNavigatorImage() {
final config = ConfigService.instance;
final imagePath = '${config.assetsPath}/navigator/${config.navigator}/default.png';
return Image.file(
File(imagePath),
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
// Graceful fallback - empty box if image missing
return const SizedBox.shrink();
},
);
}
2026-01-25 18:47:35 +09:00
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Padding(
padding: const EdgeInsets.all(32),
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: [
// Header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'SMART SEROW',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Colors.teal,
letterSpacing: 2,
),
),
Text(
'${_voltage.toStringAsFixed(1)}V',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: _voltage < 12.0 ? Colors.red : Colors.green,
),
),
],
2026-01-25 18:47:35 +09:00
),
const SizedBox(height: 48),
// Main Pi temperature display
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
_piTemp != null ? _piTemp!.toStringAsFixed(1) : '',
style: const TextStyle(
fontSize: 180,
fontWeight: FontWeight.w200,
color: Colors.white,
height: 1,
),
),
Text(
'Pi Temp',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Colors.grey,
),
),
],
),
),
2026-01-25 18:47:35 +09:00
),
// Bottom stats row
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
StatBox(label: 'RPM', value: _rpm.toString()),
StatBox(label: 'ENG', value: '$_temp°C'),
StatBox(label: 'GEAR', value: ''),
],
),
],
),
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(
2026-01-25 23:13:30 +09:00
child: _buildNavigatorImage(),
2026-01-25 18:47:35 +09:00
),
),
],
),
),
);
}
}