| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import '../services/bluetooth_service.dart';
- class DiagnosticsScreen extends ConsumerWidget {
- const DiagnosticsScreen({super.key});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final state = ref.watch(bluetoothServiceProvider);
- final service = ref.read(bluetoothServiceProvider.notifier);
- return Scaffold(
- appBar: AppBar(
- title: const Text('Diagnostics'),
- actions: [
- IconButton(
- tooltip: 'Copy log',
- icon: const Icon(Icons.copy),
- onPressed: state.diagnosticLog.isEmpty
- ? null
- : () async {
- await Clipboard.setData(
- ClipboardData(text: service.exportDiagnosticLog()),
- );
- if (context.mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('Diagnostic log copied')),
- );
- }
- },
- ),
- IconButton(
- tooltip: 'Clear log',
- icon: const Icon(Icons.delete_outline),
- onPressed: state.diagnosticLog.isEmpty
- ? null
- : service.clearDiagnosticLog,
- ),
- ],
- ),
- body: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- Padding(
- padding: const EdgeInsets.all(16),
- child: Text(
- '${state.connectionStatus}'
- '${state.transportName.isEmpty ? '' : ' - ${state.transportName}'}'
- '\nFirmware: ${state.firmwareVersion.isEmpty ? 'Unknown' : state.firmwareVersion}'
- '\nTemperature data: ${state.telemetryStale ? 'stale / unavailable' : 'live'}'
- '\nLast sample: ${state.lastTelemetryAt?.toLocal().toIso8601String() ?? 'none'}'
- '\nLast 1000 RX/TX/events, held in memory only. Nothing is uploaded.',
- ),
- ),
- if (state.commandError != null)
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Text(
- state.commandError!,
- style: const TextStyle(color: Colors.redAccent),
- ),
- ),
- const Divider(),
- Expanded(
- child: state.diagnosticLog.isEmpty
- ? const Center(child: Text('No diagnostic entries yet'))
- : ListView.builder(
- reverse: true,
- itemCount: state.diagnosticLog.length,
- itemBuilder: (context, index) {
- final entry =
- state.diagnosticLog[state.diagnosticLog.length -
- index -
- 1];
- return Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 4,
- ),
- child: SelectableText(
- entry.text,
- style: const TextStyle(
- fontFamily: 'monospace',
- fontSize: 12,
- ),
- ),
- );
- },
- ),
- ),
- ],
- ),
- );
- }
- }
|