blob: 4091bb3d8f95529d15e88025217ec2cc5ed20024 (
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
|
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),
];
Timer? _timer;
AppState() {
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
toggleFirstContact();
});
}
void toggleFirstContact() {
if (contacts.isEmpty) {
return;
}
contacts[0].isOpen = !contacts[0].isOpen;
notifyListeners();
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
}
class Contact {
final String address;
bool isOpen;
Contact({required this.address, required this.isOpen});
}
|