blob: c0d640fa0a3f7240d67f54707ece471d0f7ad6c4 (
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
|
import 'dart:async';
import 'package:flutter/foundation.dart';
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();
}
}
|