import 'dart:async'; import 'package:flutter/foundation.dart'; class AppState with ChangeNotifier { Map contacts = { '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(); } }