- Implemented RawFrameDebugScreen for displaying ECU frame data and diagnostics. - Created DtcScreen to show active Diagnostic Trouble Codes (DTCs) with detailed descriptions. - Added DtcRow widget for individual DTC representation. - Introduced GraphScreen for visualizing sensor data over time with customizable time windows. - Developed SensorListScreen to display available sensors and their current values. - Enhanced SettingsScreen with options for Bluetooth connection, ECU protocol selection, polling interval, and theme settings. - Added AppColors and AppTheme for consistent theming across the application. - Implemented BtStatusChip to show Bluetooth connection status in the app bar. - Created RecordFab for starting and stopping data recording sessions.
93 lines
3.2 KiB
Dart
93 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../../core/protocol/dtc_map.dart';
|
|
import '../../../core/providers/sensor_provider.dart';
|
|
import '../../../core/providers/settings_provider.dart';
|
|
import '../../../core/bluetooth/bt_poller.dart';
|
|
import 'widgets/dtc_row.dart';
|
|
|
|
class DtcScreen extends ConsumerWidget {
|
|
const DtcScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final state = ref.watch(latestSensorProvider);
|
|
final ecuType = ref.watch(settingsProvider).ecuType;
|
|
|
|
final dtcMap =
|
|
ecuType == EcuType.s300 ? s300DtcMap : kproDtcMap;
|
|
final active = decodeDtcs(state.errBytes, dtcMap);
|
|
|
|
return Column(
|
|
children: [
|
|
// Header bar
|
|
Container(
|
|
color: const Color(0xFF1A1A1A),
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
active.isEmpty
|
|
? Icons.check_circle_outline
|
|
: Icons.warning_amber_rounded,
|
|
color: active.isEmpty ? Colors.green : Colors.amber,
|
|
size: 18,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
active.isEmpty
|
|
? 'No active fault codes'
|
|
: '${active.length} active DTC${active.length > 1 ? "s" : ""}',
|
|
style: TextStyle(
|
|
color: active.isEmpty ? Colors.green : Colors.amber,
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Text(
|
|
ecuType == EcuType.s300 ? 'S300' : 'KPro',
|
|
style:
|
|
const TextStyle(color: Colors.grey, fontSize: 12),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Divider(height: 1, color: Colors.white10),
|
|
|
|
// DTC list
|
|
Expanded(
|
|
child: active.isEmpty
|
|
? const Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.check_circle_outline,
|
|
size: 56, color: Colors.green),
|
|
SizedBox(height: 12),
|
|
Text('All clear — no fault codes',
|
|
style: TextStyle(
|
|
color: Colors.grey, fontSize: 15)),
|
|
],
|
|
),
|
|
)
|
|
: ListView.separated(
|
|
itemCount: active.length,
|
|
separatorBuilder: (_, __) =>
|
|
const Divider(height: 1, color: Colors.white10),
|
|
itemBuilder: (context, i) {
|
|
final full = active[i]; // "P0130 — O2 Sensor (front)"
|
|
final parts = full.split(' — ');
|
|
final code = parts.first.trim();
|
|
final desc =
|
|
parts.length > 1 ? parts.sublist(1).join(' — ') : '';
|
|
return DtcRow(code: code, description: desc);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|