diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/data.dart | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/data.dart b/lib/data.dart index 5cd59ec..4091bb3 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/foundation.dart'; class AppState with ChangeNotifier { @@ -7,6 +9,29 @@ class AppState with ChangeNotifier { 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 { |
