blob: f8b74661f86bcee3c887cf1a0b5d0872389f55da (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import 'dart:async';
import 'package:flutter/foundation.dart';
const String brokerHostname = 'sia.xengineering.eu';
const int brokerPort = 1883;
const String topicPrefix = 'sia';
class AppState with ChangeNotifier {
Map<String, bool> contacts = <String, bool>{
'Living Room Window': false,
'Front Door': true,
'Back Door': false,
'Garage Window': true,
};
Timer? _timer;
AppState() {
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
toggleFirstContact();
});
}
void toggleFirstContact() {
if (contacts.isEmpty) {
return;
}
const String choosen = 'Living Room Window';
bool? state = contacts[choosen];
if (state != null) {
contacts[choosen] = !state;
notifyListeners();
}
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
}
|