Compare commits
No commits in common. "99cc98f8533b0fb9fe8ea1d87a3c04043e9a616b" and "87462fa2051ad46b8f630a672761d25242eb5381" have entirely different histories.
99cc98f853
...
87462fa205
@ -1 +0,0 @@
|
|||||||
extensions:
|
|
@ -1,28 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
extension TimeExtensions on DateTime {
|
|
||||||
DateTime forwardTo(TimeOfDay timeOfDay) {
|
|
||||||
final now = DateTime.now();
|
|
||||||
final today = DateTime(now.year, now.month, now.day);
|
|
||||||
DateTime result;
|
|
||||||
|
|
||||||
final targetTime = DateTime(now.year, now.month, now.day, timeOfDay.hour, timeOfDay.minute);
|
|
||||||
if (targetTime.isBefore(now) || targetTime.isAtSameMomentAs(now)) {
|
|
||||||
result = today.add(Duration(days: 1));
|
|
||||||
} else {
|
|
||||||
result = today;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.add(Duration(hours: timeOfDay.hour, minutes: timeOfDay.minute));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isBetweenTimeOfDay(TimeOfDay start, TimeOfDay end) {
|
|
||||||
final now = this;
|
|
||||||
final today = DateTime(now.year, now.month, now.day);
|
|
||||||
|
|
||||||
final startTime = today.add(Duration(hours: start.hour, minutes: start.minute));
|
|
||||||
final endTime = today.add(Duration(hours: end.hour, minutes: end.minute));
|
|
||||||
|
|
||||||
return now.isAfter(startTime) && now.isBefore(endTime);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
import 'package:app/state/timeStatusState.dart';
|
import 'package:app/state/legalStatusState.dart';
|
||||||
import 'package:app/state/mapState.dart';
|
import 'package:app/state/mapState.dart';
|
||||||
import 'package:app/view/home.dart';
|
import 'package:app/view/home.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -8,7 +8,7 @@ void main() {
|
|||||||
runApp(
|
runApp(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider<TimeStatusState>(create: (context) => TimeStatusState()),
|
ChangeNotifierProvider<LegalStatusState>(create: (context) => LegalStatusState()),
|
||||||
ChangeNotifierProvider<MapState>(create: (context) => MapState()),
|
ChangeNotifierProvider<MapState>(create: (context) => MapState()),
|
||||||
],
|
],
|
||||||
builder: (context, child) => const MyApp(),
|
builder: (context, child) => const MyApp(),
|
||||||
|
61
lib/state/legalStatusState.dart
Normal file
61
lib/state/legalStatusState.dart
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
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,14 +1,11 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_map/flutter_map.dart';
|
|
||||||
|
|
||||||
class MapState extends ChangeNotifier {
|
class MapState extends ChangeNotifier {
|
||||||
bool _isLocationLock = false;
|
bool _isLocationLock = false;
|
||||||
bool _isCurrentlyFetchin = false;
|
bool _isCurrentlyFetchin = true;
|
||||||
final MapController _mapController = MapController();
|
|
||||||
|
|
||||||
bool get followLocation => _isLocationLock;
|
bool get followLocation => _isLocationLock;
|
||||||
bool get isCurrentlyFetching => _isCurrentlyFetchin;
|
bool get isCurrentlyFetching => _isCurrentlyFetchin;
|
||||||
MapController get getMapController => _mapController;
|
|
||||||
|
|
||||||
toggleLocationLock() {
|
toggleLocationLock() {
|
||||||
_isLocationLock = !_isLocationLock;
|
_isLocationLock = !_isLocationLock;
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
import 'package:app/extensions/obtainProviderExtension.dart';
|
import 'package:app/extensions/obtainProviderExtension.dart';
|
||||||
import 'package:app/state/mapState.dart';
|
import 'package:app/state/mapState.dart';
|
||||||
import 'package:app/state/timeStatusState.dart';
|
|
||||||
import 'package:app/util/loadingContainer.dart';
|
import 'package:app/util/loadingContainer.dart';
|
||||||
import 'package:app/util/watchState.dart';
|
import 'package:app/util/watchState.dart';
|
||||||
import 'package:app/view/appInfo.dart';
|
import 'package:app/view/appInfo.dart';
|
||||||
@ -48,14 +46,10 @@ class _HomePageState extends State<HomeView> {
|
|||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
WatchState<TimeStatusState>((context, state) {
|
const SizedBox(
|
||||||
if(state.isCurrentlyLegal) return const SizedBox.shrink();
|
height: 100,
|
||||||
|
child: StatusView(),
|
||||||
return const SizedBox(
|
),
|
||||||
height: 100,
|
|
||||||
child: StatusView(),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Consumer<MapState>(
|
child: Consumer<MapState>(
|
||||||
builder: (context, state, child) {
|
builder: (context, state, child) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import 'package:app/extensions/obtainProviderExtension.dart';
|
|
||||||
import 'package:app/state/mapState.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_map/flutter_map.dart';
|
import 'package:flutter_map/flutter_map.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
@ -17,7 +15,6 @@ class _MapViewState extends State<MapView> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FlutterMap(
|
return FlutterMap(
|
||||||
mapController: context.obtainState<MapState>().getMapController,
|
|
||||||
options: const MapOptions(
|
options: const MapOptions(
|
||||||
initialCenter: LatLng(50.354, 7.5845),
|
initialCenter: LatLng(50.354, 7.5845),
|
||||||
initialZoom: 16,
|
initialZoom: 16,
|
||||||
@ -32,9 +29,9 @@ class _MapViewState extends State<MapView> {
|
|||||||
TileLayer(
|
TileLayer(
|
||||||
urlTemplate: "https://bubatzkarte.de/tiles/radius/100/{z}/{x}/{y}.png",
|
urlTemplate: "https://bubatzkarte.de/tiles/radius/100/{z}/{x}/{y}.png",
|
||||||
tileProvider: NetworkTileProvider(
|
tileProvider: NetworkTileProvider(
|
||||||
httpClient: RetryClient(
|
httpClient: RetryClient(
|
||||||
Client(),
|
Client(),
|
||||||
when: (response) => response.statusCode == 502)
|
when: (response) => response.statusCode == 502)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
import 'package:app/util/watchState.dart';
|
import 'package:app/util/watchState.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_timer_countdown/flutter_timer_countdown.dart';
|
|
||||||
|
|
||||||
import '../state/timeStatusState.dart';
|
import '../state/legalStatusState.dart';
|
||||||
|
|
||||||
class StatusView extends StatelessWidget {
|
class StatusView extends StatelessWidget {
|
||||||
const StatusView({super.key});
|
const StatusView({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WatchState<TimeStatusState>((context, state) {
|
return WatchState<LegalStatusState>((context, state) {
|
||||||
return Container(
|
return Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surface
|
color: state.info.color
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Center(
|
Center(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.timer_outlined,
|
state.info.icon,
|
||||||
size: 40,
|
size: 40,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -29,7 +28,7 @@ class StatusView extends StatelessWidget {
|
|||||||
indent: 20,
|
indent: 20,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
thickness: 3,
|
thickness: 3,
|
||||||
width: 40,
|
width: 30,
|
||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -37,22 +36,21 @@ class StatusView extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
Text(
|
||||||
"Ab 20 Uhr",
|
state.info.title,
|
||||||
style: TextStyle(fontSize: 20),
|
style: const TextStyle(fontSize: 20),
|
||||||
),
|
|
||||||
TimerCountdown(
|
|
||||||
format: CountDownTimerFormat.hoursMinutesSeconds,
|
|
||||||
enableDescriptions: false,
|
|
||||||
spacerWidth: 5,
|
|
||||||
endTime: DateTime.now().add(state.remainingTimeUntilStart),
|
|
||||||
onEnd: () {
|
|
||||||
print("Timer finished");
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
Text(state.info.subtitle),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: 20),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.info_outline),
|
||||||
|
onPressed: () {
|
||||||
|
|
||||||
|
},
|
||||||
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -163,14 +163,6 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
flutter_timer_countdown:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: flutter_timer_countdown
|
|
||||||
sha256: "0c73e1593ad7949c007752199a17e7ed50bb581568743dbc32f061f49873219e"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.7"
|
|
||||||
flutter_web_plugins:
|
flutter_web_plugins:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -41,7 +41,6 @@ dependencies:
|
|||||||
flutter_map: ^6.1.0
|
flutter_map: ^6.1.0
|
||||||
latlong2: ^0.9.0
|
latlong2: ^0.9.0
|
||||||
http: ^1.2.1
|
http: ^1.2.1
|
||||||
flutter_timer_countdown: ^1.0.7
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user