From 4bc034c7ab627c50aba7e2ce4da360c14465c150 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 8 Mar 2026 17:27:52 +0100 Subject: Switch completely to connection state machine This makes use of the state machine in the UI and implements all states and transitions planned so far. --- lib/ui.dart | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'lib/ui.dart') diff --git a/lib/ui.dart b/lib/ui.dart index e14895b..7a97f32 100644 --- a/lib/ui.dart +++ b/lib/ui.dart @@ -98,18 +98,22 @@ class ConnectionStatus extends StatelessWidget { return SafeArea( child: Consumer( builder: (BuildContext context, AppState state, Widget? child) { - Icon icon; - Text text; + Icon icon = const Icon(Icons.cloud_off, color: Colors.grey); + Text text = const Text('Disconnected'); - if (state.brokerConnected && state.serverConnected) { - icon = const Icon(Icons.cloud, color: Colors.green); - text = const Text('Connected'); - } else if (state.brokerConnected && !state.serverConnected) { - icon = const Icon(Icons.cloud_off, color: Colors.orange); - text = const Text('Connection issue'); - } else { - icon = const Icon(Icons.cloud_off, color: Colors.red); - text = const Text('Disconnected'); + switch (state.state) { + case MachineState.init: + icon = const Icon(Icons.cloud_off, color: Colors.grey); + text = const Text('Off'); + case MachineState.disconnected: + icon = const Icon(Icons.cloud_off, color: Colors.red); + text = const Text('Disconnected'); + case MachineState.unreachable: + icon = const Icon(Icons.cloud_off, color: Colors.orange); + text = const Text('Unreachable'); + case MachineState.reachable: + icon = const Icon(Icons.cloud, color: Colors.green); + text = const Text('Connected'); } MachineEvent event = MachineEvent.disconnect; -- cgit v1.3