summaryrefslogtreecommitdiffstats
path: root/lib/data/data_providers/time_notifier.dart
blob: c2905264c744f02a2f820f186b7ff010b65c0d4c (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
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;
  int? selectedYear;
  bool isYearChanged = false;

  void _initializeTimer() {
    Timer.periodic(const Duration(seconds: 1), (timer) {
      state = state.add(const Duration(seconds: 1));
    });
  }

  void setCurrentTime(DateTime newTime) {
    state = newTime;
    selectedYear = newTime.year;
  }
}