From 2e15dd323b7c3198e2af10f35f1186d91cc6cfaf Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 7 Mar 2026 13:03:24 +0100 Subject: Label button with '(dis)connect' This does not yet work but the correct text based on the page is displayed. This is based on a state machine based implementation suitable to implement the state handling cleanly. --- lib/ui.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/ui.dart') diff --git a/lib/ui.dart b/lib/ui.dart index 73e532a..e14895b 100644 --- a/lib/ui.dart +++ b/lib/ui.dart @@ -13,7 +13,7 @@ class Sia extends StatelessWidget { child: MaterialApp( home: Consumer( builder: (_, AppState provider, _) { - if (provider.onConnectionPage) { + if (provider.state == MachineState.init) { return const ConnectionPage(); } return const DevicesPage(); @@ -112,6 +112,13 @@ class ConnectionStatus extends StatelessWidget { text = const Text('Disconnected'); } + MachineEvent event = MachineEvent.disconnect; + String action = 'disconnect'; + if (state.state == MachineState.init) { + event = MachineEvent.connect; + action = 'connect'; + } + return Row( children: [ Expanded( @@ -119,8 +126,10 @@ class ConnectionStatus extends StatelessWidget { leading: icon, title: text, trailing: ElevatedButton( - onPressed: state.togglePage, - child: const Text('switch view'), + onPressed: () { + state.process(event); + }, + child: Text(action), ), ), ), -- cgit v1.3