diff options
| author | xengineering <me@xengineering.eu> | 2026-03-10 17:53:34 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-03-10 17:53:34 +0100 |
| commit | 0f32a2c2aab78b882fff10a6b81ddd271bcb17b0 (patch) | |
| tree | 70bf3b6fa5b5709c583756e2bca8e3844e47bf67 /lib/ui.dart | |
| parent | 6ee59e8c2aaf69951f6f80003c23f9cd44976ce1 (diff) | |
| download | sia-app-0f32a2c2aab78b882fff10a6b81ddd271bcb17b0.tar sia-app-0f32a2c2aab78b882fff10a6b81ddd271bcb17b0.tar.zst sia-app-0f32a2c2aab78b882fff10a6b81ddd271bcb17b0.zip | |
Make ConnectionPage a StatefulWidget
This allows to store the fully qualified domain name (FQDN) of the MQTT
broker and display it if the user visits the page again.
The old behaviour was that the text input field was empty.
Diffstat (limited to 'lib/ui.dart')
| -rw-r--r-- | lib/ui.dart | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/ui.dart b/lib/ui.dart index a191f5f..9603562 100644 --- a/lib/ui.dart +++ b/lib/ui.dart @@ -24,10 +24,35 @@ class Sia extends StatelessWidget { } } -class ConnectionPage extends StatelessWidget { +class ConnectionPage extends StatefulWidget { const ConnectionPage({super.key}); @override + State<ConnectionPage> createState() => _ConnectionPageState(); +} + +class _ConnectionPageState extends State<ConnectionPage> { + late TextEditingController controller; + + @override + void initState() { + super.initState(); + + final AppState provider = context.read<AppState>(); + controller = TextEditingController(text: provider.fqdn); + + controller.addListener(() { + provider.fqdn = controller.text; + }); + } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + @override Widget build(BuildContext context) { return Consumer<AppState>( builder: (_, AppState state, _) { @@ -36,14 +61,12 @@ class ConnectionPage extends StatelessWidget { body: Padding( padding: const EdgeInsets.all(16.0), child: TextField( + controller: controller, decoration: const InputDecoration( labelText: "Server name", hintText: "iot.example.org", border: OutlineInputBorder(), ), - onChanged: (String value) { - state.fqdn = value; - }, ), ), bottomNavigationBar: const ConnectionStatus(), |
