diff options
Diffstat (limited to 'lib/data/data_providers/time_notifier.dart')
-rw-r--r-- | lib/data/data_providers/time_notifier.dart | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/data/data_providers/time_notifier.dart b/lib/data/data_providers/time_notifier.dart new file mode 100644 index 0000000..9737b2b --- /dev/null +++ b/lib/data/data_providers/time_notifier.dart @@ -0,0 +1,24 @@ +import 'dart:async'; + +import 'package:flutter_ics_homescreen/export.dart'; + +class CurrentTimeNotifier extends StateNotifier<DateTime> { + CurrentTimeNotifier() : super(DateTime.now()) { + if (!_hasInitialized) { + _initializeTimer(); + _hasInitialized = true; + } + } + + bool _hasInitialized = false; + + void _initializeTimer() { + Timer.periodic(const Duration(seconds: 1), (timer) { + state = state.add(const Duration(seconds: 1)); + }); + } + + void setCurrentTime(DateTime newTime) { + state = newTime; + } +} |