feat: Enhance home screen layout with RX/TX indicators and device config button

This commit is contained in:
Janez T
2025-10-16 14:26:15 +02:00
parent 9ab5469759
commit c05ae8de89

View File

@@ -641,63 +641,12 @@ class _HomeScreenState extends State<HomeScreen>
], ],
), ),
), ),
if (!isConnected)
Row( Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
ElevatedButton.icon( // Advertise button (broadcast location) - always visible
onPressed: provider.isReconnecting
? null // Disable button during reconnection
: () => _showConnectionDialog(context),
icon: provider.isReconnecting
? const SizedBox(
width: 14,
height: 14,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.black54,
),
),
)
: const Icon(Icons.bluetooth, size: 18),
label: Text(
provider.isReconnecting
? 'Reconnecting (${provider.reconnectionAttempt}/${provider.maxReconnectionAttempts})'
: 'Connect',
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black87,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
// Cancel button during reconnection
if (provider.isReconnecting) ...[
const SizedBox(width: 8),
IconButton(
onPressed: () => provider.cancelReconnection(),
icon: const Icon(Icons.close, size: 20),
tooltip: 'Cancel reconnection',
style: IconButton.styleFrom(
backgroundColor: Colors.red.shade700,
foregroundColor: Colors.white,
padding: const EdgeInsets.all(8),
),
),
],
],
)
else
Row(
mainAxisSize: MainAxisSize.min,
children: [
// Advertise button (broadcast location)
FilledButton( FilledButton(
onPressed: () => _advertiseDevice(context), onPressed: isConnected ? () => _advertiseDevice(context) : null,
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
backgroundColor: Colors.blue.shade700, backgroundColor: Colors.blue.shade700,
foregroundColor: Colors.white, foregroundColor: Colors.white,
@@ -707,7 +656,34 @@ class _HomeScreenState extends State<HomeScreen>
), ),
child: const Icon(Icons.campaign, size: 20), child: const Icon(Icons.campaign, size: 20),
), ),
if (_showRxTxIndicators) ...[ const SizedBox(width: 8),
// Device config button - always visible
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DeviceConfigScreen(),
),
);
},
onLongPress: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
PacketLogScreen(bleService: provider.bleService),
),
);
},
child: Container(
width: 36,
height: 36,
alignment: Alignment.center,
child: const Icon(Icons.settings, size: 20),
),
),
if (isConnected && _showRxTxIndicators) ...[
const SizedBox(width: 8), const SizedBox(width: 8),
// RX/TX indicators with long press to open packet log // RX/TX indicators with long press to open packet log
GestureDetector( GestureDetector(
@@ -776,37 +752,54 @@ class _HomeScreenState extends State<HomeScreen>
], ],
), ),
), ),
const SizedBox(width: 12),
], ],
// Settings button (tap for device settings, long press for packet logs) const SizedBox(width: 8),
GestureDetector( // Connect/Disconnect button on the right
onTap: () { if (!isConnected)
Navigator.push( ElevatedButton.icon(
context, onPressed: provider.isReconnecting
MaterialPageRoute( ? null
builder: (context) => const DeviceConfigScreen(), : () => _showConnectionDialog(context),
), icon: provider.isReconnecting
); ? const SizedBox(
}, width: 14,
onLongPress: () { height: 14,
Navigator.push( child: CircularProgressIndicator(
context, strokeWidth: 2,
MaterialPageRoute( valueColor: AlwaysStoppedAnimation<Color>(
builder: (context) => Colors.black54,
PacketLogScreen(bleService: provider.bleService),
),
);
},
child: Container(
width: 36,
height: 36,
alignment: Alignment.center,
child: const Icon(Icons.settings, size: 20),
), ),
), ),
const SizedBox(width: 16), )
: const Icon(Icons.bluetooth, size: 18),
// Disconnect button (prominent, icon only) - pushed to far right edge label: Text(
provider.isReconnecting
? 'Reconnecting (${provider.reconnectionAttempt}/${provider.maxReconnectionAttempts})'
: 'Connect',
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black87,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
// Cancel button during reconnection
if (provider.isReconnecting) ...[
const SizedBox(width: 8),
IconButton(
onPressed: () => provider.cancelReconnection(),
icon: const Icon(Icons.close, size: 20),
tooltip: 'Cancel reconnection',
style: IconButton.styleFrom(
backgroundColor: Colors.red.shade700,
foregroundColor: Colors.white,
padding: const EdgeInsets.all(8),
),
),
],
], ],
), ),
], ],