diff options
| author | xengineering <me@xengineering.eu> | 2026-01-11 20:26:03 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-01-11 20:26:03 +0100 |
| commit | ad86cd926d5da6031930de79cbe85df7ff40df1c (patch) | |
| tree | e13de1e14ca42f31466416c3f17a2bc98f385a73 /lib/data.dart | |
| parent | 0692db03e155054c8732da49eefba44d9c7ea549 (diff) | |
| download | sia-app-ad86cd926d5da6031930de79cbe85df7ff40df1c.tar sia-app-ad86cd926d5da6031930de79cbe85df7ff40df1c.tar.zst sia-app-ad86cd926d5da6031930de79cbe85df7ff40df1c.zip | |
Switch to Map address to state for contacts
This map should be empty in the future and updated based on the incoming
MQTT messages.
A list was not the correct data structure for that since it requires to
iterate over the whole list to find the entry with a certain address.
But this is required to update the state of an already known contact.
Diffstat (limited to 'lib/data.dart')
| -rw-r--r-- | lib/data.dart | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/data.dart b/lib/data.dart index 93c523d..c0d640f 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -3,12 +3,12 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; class AppState with ChangeNotifier { - List<Contact> contacts = <Contact>[ - Contact(address: "Living Room Window", isOpen: false), - Contact(address: "Front Door", isOpen: true), - Contact(address: "Back Door", isOpen: false), - Contact(address: "Garage Window", isOpen: true), - ]; + Map<String, bool> contacts = <String, bool>{ + 'Living Room Window': false, + 'Front Door': true, + 'Back Door': false, + 'Garage Window': true, + }; Timer? _timer; @@ -23,8 +23,12 @@ class AppState with ChangeNotifier { return; } - contacts[0].isOpen = !contacts[0].isOpen; - notifyListeners(); + const String choosen = 'Living Room Window'; + bool? state = contacts[choosen]; + if (state != null) { + contacts[choosen] = !state; + notifyListeners(); + } } @override @@ -33,10 +37,3 @@ class AppState with ChangeNotifier { super.dispose(); } } - -class Contact { - final String address; - bool isOpen; - - Contact({required this.address, required this.isOpen}); -} |
