import 'package:flutter/material.dart'; import '../services/ble_service.dart'; import '../siab_config.dart'; class ConnectionCard extends StatelessWidget { final BLEService ble; const ConnectionCard({super.key, required this.ble}); @override Widget build(BuildContext context) { return Card( margin: const EdgeInsets.all(8), child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Icon( ble.isConnected ? Icons.bluetooth_connected : Icons.bluetooth_disabled, color: ble.isConnected ? Colors.green : Colors.grey, ), const SizedBox(width: 8), Text( ble.isConnected ? 'Connected' : 'Disconnected', style: Theme.of(context).textTheme.titleLarge, ), const Spacer(), if (ble.isScanning || ble.isConnecting) const SizedBox( width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2), ), ], ), if (ble.isConnected) ...[ const SizedBox(height: 8), if (ble.deviceName != null) Text('Device: ${ble.deviceName}'), if (ble.deviceAddress != null) Text( 'Address: ${ble.deviceAddress}', style: Theme.of(context).textTheme.bodySmall, ), ], if (!ble.isConnected && !ble.isScanning && !ble.isConnecting) ...[ const SizedBox(height: 8), SizedBox( width: double.infinity, child: ElevatedButton.icon( onPressed: () async { final success = await ble.autoConnect(); if (!success && context.mounted) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( 'Failed to find ${SiabConfig.deviceName} device', ), backgroundColor: Colors.orange, ), ); } }, icon: const Icon(Icons.search), label: const Text('Scan & Connect'), ), ), ], ], ), ), ); } }