From 10b0c59c3f192ce8eeb22d36963b855ebfb62b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Tue, 26 Mar 2024 20:50:57 +0100 Subject: [PATCH] added legal state bar content --- lib/model/stateInfo.dart | 11 +++++++ lib/state/legalStatusState.dart | 45 ++++++++++++++++++++++++- lib/util/watchState.dart | 12 +++++++ lib/view/appInfo.dart | 15 +++++++++ lib/view/home.dart | 27 ++++++++++++--- lib/view/legalStatus.dart | 21 ------------ lib/view/status.dart | 58 +++++++++++++++++++++++++++++---- 7 files changed, 155 insertions(+), 34 deletions(-) create mode 100644 lib/model/stateInfo.dart create mode 100644 lib/util/watchState.dart create mode 100644 lib/view/appInfo.dart delete mode 100644 lib/view/legalStatus.dart diff --git a/lib/model/stateInfo.dart b/lib/model/stateInfo.dart new file mode 100644 index 0000000..7f58902 --- /dev/null +++ b/lib/model/stateInfo.dart @@ -0,0 +1,11 @@ +import 'package:flutter/cupertino.dart'; + +class StateInfo { + IconData icon; + Color color; + String title; + String subtitle; + String description; + + StateInfo({required this.icon, required this.color, required this.title, required this.subtitle, required this.description}); +} \ No newline at end of file diff --git a/lib/state/legalStatusState.dart b/lib/state/legalStatusState.dart index 2d0eb30..ebbcb8b 100644 --- a/lib/state/legalStatusState.dart +++ b/lib/state/legalStatusState.dart @@ -1,11 +1,54 @@ import 'package:app/model/legelState.dart'; -import 'package:flutter/cupertino.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(); diff --git a/lib/util/watchState.dart b/lib/util/watchState.dart new file mode 100644 index 0000000..5c85d3f --- /dev/null +++ b/lib/util/watchState.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class WatchState extends StatelessWidget { + final Widget Function(BuildContext context, T state) child; + const WatchState(this.child, {super.key}); + + @override + Widget build(BuildContext context) { + return Consumer(builder: (BuildContext context, T value, Widget? child) => this.child(context, value)); + } +} diff --git a/lib/view/appInfo.dart b/lib/view/appInfo.dart new file mode 100644 index 0000000..835f78e --- /dev/null +++ b/lib/view/appInfo.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.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"), + ), + ); + } +} diff --git a/lib/view/home.dart b/lib/view/home.dart index 3fbf7d5..a38b1b3 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -1,9 +1,10 @@ import 'package:app/extensions/obtainProviderExtension.dart'; import 'package:app/state/mapState.dart'; -import 'package:app/view/legalStatus.dart'; +import 'package:app/util/watchState.dart'; +import 'package:app/view/appInfo.dart'; +import 'package:app/view/status.dart'; import 'package:app/view/map.dart'; import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; class HomeView extends StatefulWidget { const HomeView({super.key}); @@ -19,17 +20,33 @@ class _HomePageState extends State { appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: const Text("Bubatzkarte"), - actions: [], + actions: [ + IconButton( + icon: const Icon(Icons.search), + onPressed: () { + + }, + ), + IconButton( + icon: const Icon(Icons.info_outline), + onPressed: () { + showDialog( + context: context, + builder: (context) => const AppInfoView(), + ); + }, + ), + ], ), floatingActionButton: FloatingActionButton( - child: Consumer(builder: (context, value, child) => Icon(value.followLocation ? Icons.my_location : Icons.location_disabled)), + child: WatchState((context, state) => Icon(state.followLocation ? Icons.my_location : Icons.location_disabled)), onPressed: () => context.obtainState().toggleLocationLock(), ), body: const Column( children: [ SizedBox( height: 100, - child: LegalStatusView(), + child: StatusView(), ), Expanded( child: MapView(), diff --git a/lib/view/legalStatus.dart b/lib/view/legalStatus.dart deleted file mode 100644 index 1dfbdd8..0000000 --- a/lib/view/legalStatus.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:app/state/legalStatusState.dart'; -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -class LegalStatusView extends StatefulWidget { - const LegalStatusView({super.key}); - - @override - State createState() => _LegalStatusViewState(); -} - -class _LegalStatusViewState extends State { - @override - Widget build(BuildContext context) { - return Consumer( - builder: (context, value, child) { - return Placeholder(); - }, - ); - } -} diff --git a/lib/view/status.dart b/lib/view/status.dart index a2b330b..81c4a40 100644 --- a/lib/view/status.dart +++ b/lib/view/status.dart @@ -1,15 +1,59 @@ +import 'package:app/util/watchState.dart'; import 'package:flutter/material.dart'; -class StatusView extends StatefulWidget { +import '../state/legalStatusState.dart'; + +class StatusView extends StatelessWidget { const StatusView({super.key}); - @override - State createState() => _StatusViewState(); -} - -class _StatusViewState extends State { @override Widget build(BuildContext context) { - return const Placeholder(); + return WatchState((context, state) { + return Container( + decoration: BoxDecoration( + color: state.info.color + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Center( + child: Icon( + state.info.icon, + size: 40, + ), + ), + const VerticalDivider( + endIndent: 20, + indent: 20, + color: Colors.white, + thickness: 3, + width: 30, + ), + Center( + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + state.info.title, + style: const TextStyle(fontSize: 20), + ), + Text(state.info.subtitle), + ], + ), + ), + const SizedBox(width: 20), + IconButton( + icon: const Icon(Icons.info_outline), + onPressed: () { + + }, + ) + ], + ) + ); + }); } }