import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../core/providers/bt_provider.dart'; /// Thin banner under the app bar that tells the driver when the numbers on /// screen are NOT live, instead of silently showing stale or default values. class DataStatusBanner extends ConsumerWidget { const DataStatusBanner({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final status = ref.watch(btProvider.select((s) => s.status)); final data = ref.watch(btProvider.select((s) => s.dataStatus)); final error = ref.watch(btProvider.select((s) => s.error)); final String? msg; Color color = const Color(0xFF8A5A00); if (status == BtStatus.reconnecting) { msg = 'Connection interrupted — reconnecting…'; } else if (status == BtStatus.error) { msg = error ?? 'Connection lost'; color = const Color(0xFF7A0000); } else if (status == BtStatus.disconnected) { msg = 'Not connected'; color = const Color(0xFF444444); } else if (status != BtStatus.connected) { msg = null; } else { msg = switch (data) { EcuDataStatus.live => null, EcuDataStatus.none => 'Connected — waiting for data…', EcuDataStatus.adapterDefaults => 'Adapter connected, but no data from the ECU (ignition on?)', EcuDataStatus.noResponse => 'Adapter is not responding', }; } if (msg == null) return const SizedBox.shrink(); return Material( color: color, child: SizedBox( width: double.infinity, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), child: Text( msg, style: const TextStyle(color: Colors.white, fontSize: 12), ), ), ), ); } }