aboutsummaryrefslogtreecommitdiffstats
path: root/lib/data/data_providers/time_notifier.dart
blob: 9737b2b40acb2baa3e611b673283c2ced72cd945 (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
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;
  }
}