wip countdown timer
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
import 'package:app/model/legelState.dart';
|
||||
import 'package:app/model/stateInfo.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LegalStatusState extends ChangeNotifier {
|
||||
LegalState _legalState = LegalState.unknown;
|
||||
|
||||
LegalState get getLegalState => _legalState;
|
||||
|
||||
StateInfo get info {
|
||||
switch(_legalState) {
|
||||
case LegalState.allowed:
|
||||
return StateInfo(
|
||||
icon: Icons.check,
|
||||
color: Colors.lightGreen,
|
||||
title: "Passt",
|
||||
subtitle: "Alle kriterien erfüllt",
|
||||
description: "asd"
|
||||
);
|
||||
|
||||
case LegalState.disallowedTime:
|
||||
return StateInfo(
|
||||
icon: Icons.timer_outlined,
|
||||
color: Colors.amber,
|
||||
title: "Zu früh",
|
||||
subtitle: "Bubazen ist nur zwischn 20 und 6 uhr Abends/ Nachts erlaubt!",
|
||||
description: "asd"
|
||||
);
|
||||
|
||||
case LegalState.disallowedRegion:
|
||||
return StateInfo(
|
||||
icon: Icons.location_off_outlined,
|
||||
color: Colors.red,
|
||||
title: "Zu nah an einem geschützen Gebäude",
|
||||
subtitle: "asd",
|
||||
description: "asd"
|
||||
);
|
||||
|
||||
case LegalState.unknown:
|
||||
default:
|
||||
return StateInfo(
|
||||
icon: Icons.question_mark_outlined,
|
||||
color: Colors.grey,
|
||||
title: "Status nicht bekannt",
|
||||
subtitle: "asd",
|
||||
description: "asd"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set setInSightOfDisallowedAreas(bool isInSight) {
|
||||
_legalState = LegalState.disallowedRegion;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set setIsInDisallowedTimeRanges(bool isInDisallowedTime) {
|
||||
_legalState = LegalState.disallowedTime;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
@@ -1,11 +1,14 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
|
||||
class MapState extends ChangeNotifier {
|
||||
bool _isLocationLock = false;
|
||||
bool _isCurrentlyFetchin = true;
|
||||
bool _isCurrentlyFetchin = false;
|
||||
final MapController _mapController = MapController();
|
||||
|
||||
bool get followLocation => _isLocationLock;
|
||||
bool get isCurrentlyFetching => _isCurrentlyFetchin;
|
||||
MapController get getMapController => _mapController;
|
||||
|
||||
toggleLocationLock() {
|
||||
_isLocationLock = !_isLocationLock;
|
||||
|
46
lib/state/timeStatusState.dart
Normal file
46
lib/state/timeStatusState.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user