updated info text and time warning
This commit is contained in:
@ -1,46 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TimeStatusState extends ChangeNotifier {
|
||||
final TimeOfDay legalStart = const TimeOfDay(hour: 20, minute: 00);
|
||||
final TimeOfDay legalEnd = const TimeOfDay(hour: 07, minute: 00);
|
||||
class TimeWarningState extends ChangeNotifier {
|
||||
bool _show = true;
|
||||
|
||||
late Timer _refreshTimer;
|
||||
|
||||
TimeStatusState() {
|
||||
_refreshTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
bool get isCurrentlyLegal {
|
||||
final now = TimeOfDay.now();
|
||||
final currentTime = DateTime.now();
|
||||
|
||||
final startDateTime = DateTime(currentTime.year, currentTime.month, currentTime.day, legalStart.hour, legalStart.minute);
|
||||
final currentDateTime = currentTime.subtract(Duration(hours: now.hour, minutes: now.minute));
|
||||
|
||||
return currentDateTime.isBefore(startDateTime);
|
||||
}
|
||||
|
||||
Duration get remainingTimeUntilStart {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final targetDateTime = today.add(Duration(hours: legalStart.hour, minutes: legalStart.minute));
|
||||
|
||||
if (now.isBefore(targetDateTime)) {
|
||||
return targetDateTime.difference(now);
|
||||
} else {
|
||||
final nextDay = today.add(const Duration(days: 1));
|
||||
final nextTargetDateTime = nextDay.add(Duration(hours: legalStart.hour, minutes: legalStart.minute));
|
||||
return nextTargetDateTime.difference(now);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_refreshTimer.cancel();
|
||||
super.dispose();
|
||||
bool get show => _show;
|
||||
void hide() {
|
||||
_show = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user