From e748df092c80fe0d1d9fa7ede2f58ecd2fa54dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Wed, 27 Mar 2024 19:30:54 +0100 Subject: [PATCH] updated info text and time warning --- lib/main.dart | 2 +- lib/state/timeStatusState.dart | 47 ++++-------------------- lib/view/appInfo.dart | 35 +++++++++++++++--- lib/view/home.dart | 10 +++--- lib/view/status.dart | 61 ------------------------------- lib/view/timeWarning.dart | 57 +++++++++++++++++++++++++++++ pubspec.lock | 66 +++++++++++++++++++++++++++++++++- pubspec.yaml | 1 + 8 files changed, 166 insertions(+), 113 deletions(-) delete mode 100644 lib/view/status.dart create mode 100644 lib/view/timeWarning.dart diff --git a/lib/main.dart b/lib/main.dart index fbb3799..bc0948e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,7 +8,7 @@ void main() { runApp( MultiProvider( providers: [ - ChangeNotifierProvider(create: (context) => TimeStatusState()), + ChangeNotifierProvider(create: (context) => TimeWarningState()), ChangeNotifierProvider(create: (context) => MapState()), ], builder: (context, child) => const MyApp(), diff --git a/lib/state/timeStatusState.dart b/lib/state/timeStatusState.dart index 7518af7..4cb8f7c 100644 --- a/lib/state/timeStatusState.dart +++ b/lib/state/timeStatusState.dart @@ -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(); } } \ No newline at end of file diff --git a/lib/view/appInfo.dart b/lib/view/appInfo.dart index 835f78e..ef68243 100644 --- a/lib/view/appInfo.dart +++ b/lib/view/appInfo.dart @@ -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(), + ), + ], ); } } diff --git a/lib/view/home.dart b/lib/view/home.dart index 402fe43..dc8c78e 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -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 { IconButton( icon: const Icon(Icons.search), onPressed: () async { + MapState mapState = context.obtainState(); LatLng? latLng = await showSearch( context: context, delegate: LocationSearchDelegate(), ); - MapState mapState = context.obtainState(); mapState.setActiveMarker(latLng); if (latLng != null) { mapState.getMapController.move(latLng, 16); @@ -112,12 +112,12 @@ class _HomePageState extends State { ), body: Column( children: [ - WatchState((context, state) { - if(state.isCurrentlyLegal) return const SizedBox.shrink(); + WatchState((context, state) { + if(!state.show) return const SizedBox.shrink(); return const SizedBox( height: 100, - child: StatusView(), + child: TimeWarningView(), ); }), const Expanded( diff --git a/lib/view/status.dart b/lib/view/status.dart deleted file mode 100644 index 4f0679e..0000000 --- a/lib/view/status.dart +++ /dev/null @@ -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((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"); - }, - ), - ], - ), - ), - ], - ) - ); - }); - } -} diff --git a/lib/view/timeWarning.dart b/lib/view/timeWarning.dart new file mode 100644 index 0000000..7d5aad0 --- /dev/null +++ b/lib/view/timeWarning.dart @@ -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().hide, + icon: const Icon(Icons.close) + ), + ) + ], + ) + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index a82d0ed..194c0d1 100644 --- a/pubspec.lock +++ b/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" diff --git a/pubspec.yaml b/pubspec.yaml index 555e242..1815509 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: