updated info text and time warning
This commit is contained in:
parent
4ecf44bafa
commit
e748df092c
@ -8,7 +8,7 @@ void main() {
|
||||
runApp(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<TimeStatusState>(create: (context) => TimeStatusState()),
|
||||
ChangeNotifierProvider<TimeWarningState>(create: (context) => TimeWarningState()),
|
||||
ChangeNotifierProvider<MapState>(create: (context) => MapState()),
|
||||
],
|
||||
builder: (context, child) => const MyApp(),
|
||||
|
@ -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) {
|
||||
bool get show => _show;
|
||||
void hide() {
|
||||
_show = false;
|
||||
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,15 +1,42 @@
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class AppInfoView extends StatelessWidget {
|
||||
const AppInfoView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const AlertDialog(
|
||||
title: Text("Achtung"),
|
||||
content: Flexible(
|
||||
child: Text("bla"),
|
||||
return AlertDialog(
|
||||
title: const Text("Information"),
|
||||
content: const Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("Diese App zeigt die Konsumverbotszonen für Cannabis."),
|
||||
Text("Keinerlei Gewähr für Vollständigkeit, Richtigkeit und Aktualität!"),
|
||||
SizedBox(height: 10),
|
||||
Text("Prüfe selbst die Gesetzlichen Bestimmungen vor dem Besitz oder Konsum von Cannabis!", style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 10),
|
||||
Text("Die Daten beruhen auf OpenStreetMap, bearbeitet durch bubatzkarte.de."),
|
||||
Text("Es besteht keinerlei Kooperation mit OpenStreetMap oder bubatzkarte.de.")
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text("bubatzkarte.de öffnen"),
|
||||
onPressed: () => launchUrl(Uri.parse("https://bubatzkarte.de/")),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("openstreetmap.org öffnen"),
|
||||
onPressed: () => launchUrl(Uri.parse("https://www.openstreetmap.org/")),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("Schließen"),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import 'package:app/state/timeStatusState.dart';
|
||||
import 'package:app/util/watchState.dart';
|
||||
import 'package:app/view/appInfo.dart';
|
||||
import 'package:app/view/locationSearch.dart';
|
||||
import 'package:app/view/status.dart';
|
||||
import 'package:app/view/timeWarning.dart';
|
||||
import 'package:app/view/map.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
@ -66,11 +66,11 @@ class _HomePageState extends State<HomeView> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () async {
|
||||
MapState mapState = context.obtainState<MapState>();
|
||||
LatLng? latLng = await showSearch<LatLng?>(
|
||||
context: context,
|
||||
delegate: LocationSearchDelegate(),
|
||||
);
|
||||
MapState mapState = context.obtainState<MapState>();
|
||||
mapState.setActiveMarker(latLng);
|
||||
if (latLng != null) {
|
||||
mapState.getMapController.move(latLng, 16);
|
||||
@ -112,12 +112,12 @@ class _HomePageState extends State<HomeView> {
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
WatchState<TimeStatusState>((context, state) {
|
||||
if(state.isCurrentlyLegal) return const SizedBox.shrink();
|
||||
WatchState<TimeWarningState>((context, state) {
|
||||
if(!state.show) return const SizedBox.shrink();
|
||||
|
||||
return const SizedBox(
|
||||
height: 100,
|
||||
child: StatusView(),
|
||||
child: TimeWarningView(),
|
||||
);
|
||||
}),
|
||||
const Expanded(
|
||||
|
@ -1,61 +0,0 @@
|
||||
import 'package:app/util/watchState.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_timer_countdown/flutter_timer_countdown.dart';
|
||||
|
||||
import '../state/timeStatusState.dart';
|
||||
|
||||
class StatusView extends StatelessWidget {
|
||||
const StatusView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WatchState<TimeStatusState>((context, state) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Center(
|
||||
child: Icon(
|
||||
Icons.timer_outlined,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
const VerticalDivider(
|
||||
endIndent: 20,
|
||||
indent: 20,
|
||||
color: Colors.white,
|
||||
thickness: 3,
|
||||
width: 40,
|
||||
),
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
"Ab 20 Uhr",
|
||||
style: TextStyle(fontSize: 20),
|
||||
),
|
||||
TimerCountdown(
|
||||
format: CountDownTimerFormat.hoursMinutesSeconds,
|
||||
enableDescriptions: false,
|
||||
spacerWidth: 5,
|
||||
endTime: DateTime.now().add(state.remainingTimeUntilStart),
|
||||
onEnd: () {
|
||||
print("Timer finished");
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
57
lib/view/timeWarning.dart
Normal file
57
lib/view/timeWarning.dart
Normal file
@ -0,0 +1,57 @@
|
||||
import 'package:app/extensions/obtainProviderExtension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../state/timeStatusState.dart';
|
||||
|
||||
class TimeWarningView extends StatelessWidget {
|
||||
const TimeWarningView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Center(
|
||||
child: Icon(
|
||||
Icons.warning_amber,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
const VerticalDivider(
|
||||
endIndent: 20,
|
||||
indent: 20,
|
||||
color: Colors.white,
|
||||
thickness: 3,
|
||||
width: 40,
|
||||
),
|
||||
const Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"In Fußgängerzone?",
|
||||
style: TextStyle(fontSize: 20),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
"hier ist der Konsum nur\nzwischen 20 und 7 Uhr gestattet!",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Center(
|
||||
child: IconButton(
|
||||
onPressed: context.obtainState<TimeWarningState>().hide,
|
||||
icon: const Icon(Icons.close)
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
66
pubspec.lock
66
pubspec.lock
@ -533,6 +533,70 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
url_launcher:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: "0ecc004c62fd3ed36a2ffcbe0dd9700aee63bd7532d0b642a488b1ec310f492e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.5"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
sha256: d4ed0711849dd8e33eb2dd69c25db0d0d3fdc37e0a62e629fe32f57a22db2745
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.0"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_ios
|
||||
sha256: "9149d493b075ed740901f3ee844a38a00b33116c7c5c10d7fb27df8987fb51d5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.5"
|
||||
url_launcher_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_linux
|
||||
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
url_launcher_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_macos
|
||||
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
url_launcher_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_platform_interface
|
||||
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_windows
|
||||
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
uuid:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -591,4 +655,4 @@ packages:
|
||||
version: "3.1.2"
|
||||
sdks:
|
||||
dart: ">=3.3.2 <4.0.0"
|
||||
flutter: ">=3.10.0"
|
||||
flutter: ">=3.19.0"
|
||||
|
@ -44,6 +44,7 @@ dependencies:
|
||||
flutter_timer_countdown: ^1.0.7
|
||||
geolocator: ^11.0.0
|
||||
osm_nominatim: ^3.0.0
|
||||
url_launcher: ^6.2.5
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Reference in New Issue
Block a user