From b0dd1afb436b7dab6287d03fcdfa45a8bf5bc0ae Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Mon, 12 Feb 2024 12:08:45 +0100 Subject: [PATCH] Erweiterungen --- lib/content_views/task_list_page.dart | 9 +- lib/main.dart | 15 ++- lib/messages/PopContentViewMessage.dart | 5 + lib/popups/tasks_popups/signature_popup.dart | 118 ++++++++----------- 4 files changed, 68 insertions(+), 79 deletions(-) create mode 100644 lib/messages/PopContentViewMessage.dart diff --git a/lib/content_views/task_list_page.dart b/lib/content_views/task_list_page.dart index f8ca2e4..ca80b77 100644 --- a/lib/content_views/task_list_page.dart +++ b/lib/content_views/task_list_page.dart @@ -3,8 +3,10 @@ import 'package:flutter/services.dart'; import 'package:intl/intl.dart'; import 'package:isar/isar.dart'; import 'package:kumi_popup_window/kumi_popup_window.dart'; +import 'package:stadtbote/content_views/tour_list_page.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; import 'package:stadtbote/content_views/utils/header_info.dart'; +import 'package:stadtbote/messages/PopContentViewMessage.dart'; import 'package:stadtbote/model/job.dart'; import 'package:stadtbote/model/job_tour.dart'; import 'package:stadtbote/popups/tasks_popups/arrived_popup.dart'; @@ -19,6 +21,7 @@ import 'package:stadtbote/protocoll_messages/accept_job_message.dart'; import 'package:stadtbote/protocoll_messages/fin_task_message.dart'; import 'package:stadtbote/protocoll_messages/fin_tour_message.dart'; import 'package:stadtbote/tools/constants.dart'; +import 'package:stadtbote/tools/message_service.dart'; import 'package:stadtbote/tools/mqtt_core.dart'; import '../main.dart'; @@ -337,7 +340,7 @@ class _TaskListPageState extends State { SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]); Future.delayed(const Duration(seconds: 1), () async { - _popup = showSignaturePopup(context, taskInfo, () { + showSignaturePopup(context, taskInfo, () { taskInfo.completed = true; SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -346,7 +349,7 @@ class _TaskListPageState extends State { _finishTaskProcessing(taskInfo); - _popup.dismiss(context); + MessageService().publish(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 2)); }); }); } @@ -425,7 +428,5 @@ class _TaskListPageState extends State { await MyApp.isarInstance.writeTxn(() async { await MyApp.isarInstance.jobs.put(widget.job); }); - - Navigator.of(context).popUntil((route) => route.isFirst); } } diff --git a/lib/main.dart b/lib/main.dart index c601e2d..06e0652 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; import 'package:isar/isar.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:stadtbote/messages/PopContentViewMessage.dart'; import 'package:stadtbote/model/message.dart'; import 'package:stadtbote/model/status.dart'; import 'package:stadtbote/model/task_info.dart'; @@ -165,7 +166,7 @@ class _MainState extends State
with SingleTickerProviderStateMixin { _leftButtonVisible = false; _leftIconButton = const Icon(Icons.arrow_back, size: 20.0, color: Colors.white); _leftButtonOnPressed = () { - _popContentView(); + _popContentView(1); }; _rightButtonVisible = headerInfo.rightButtonVisible; @@ -191,7 +192,7 @@ class _MainState extends State
with SingleTickerProviderStateMixin { child: WillPopScope( onWillPop: () async { if (contentStack.isNotEmpty) { - _popContentView(); + _popContentView(1); return false; } else { @@ -314,8 +315,8 @@ class _MainState extends State
with SingleTickerProviderStateMixin { MessageService().subscribe(Constants.messageTopicPushContentView, this, (ContentViewWidget widget) { _pushContentView(widget); }); - MessageService().subscribe(Constants.messageTopicPopContentView, this, (ContentViewWidget widget) { - _popContentView(); + MessageService().subscribe(Constants.messageTopicPopContentView, this, (PopContentViewMessage message) { + _popContentView(message.count); }); MessageService().subscribe(Constants.messageTopicReplaceContentView, this, (ContentViewWidget widget) { _replaceContentView(widget); @@ -354,8 +355,12 @@ class _MainState extends State
with SingleTickerProviderStateMixin { }); } - void _popContentView() { + void _popContentView(int count) { Future.delayed(const Duration(seconds: 0), () async { + for (int i = 0; i < count - 1; i++) { + contentStack.pop(); + } + var previousContentView = contentStack.pop(); _currentContent = previousContentView; diff --git a/lib/messages/PopContentViewMessage.dart b/lib/messages/PopContentViewMessage.dart new file mode 100644 index 0000000..909152b --- /dev/null +++ b/lib/messages/PopContentViewMessage.dart @@ -0,0 +1,5 @@ +class PopContentViewMessage { + late int count; + + PopContentViewMessage({required this.count}); +} \ No newline at end of file diff --git a/lib/popups/tasks_popups/signature_popup.dart b/lib/popups/tasks_popups/signature_popup.dart index 7c9a3e6..9de8272 100644 --- a/lib/popups/tasks_popups/signature_popup.dart +++ b/lib/popups/tasks_popups/signature_popup.dart @@ -4,76 +4,54 @@ import 'package:signature/signature.dart'; import 'package:stadtbote/model/task_info.dart'; import 'package:stadtbote/tools/util.dart'; -KumiPopupWindow showSignaturePopup(BuildContext context, TaskInfo taskInfo, Function() onFinished) { - return showPopupWindow( - context, - //childSize:Size(240, MediaQuery.of(context).size.width * 0.8), - gravity: KumiPopupGravity.center, - //curve: Curves.elasticOut, - bgColor: Colors.grey.withOpacity(0.5), - clickOutDismiss: false, - clickBackDismiss: true, - customAnimation: false, - customPop: false, - customPage: false, - // targetRenderBox: (btnKey.currentContext.findRenderObject() as RenderBox), - //needSafeDisplay: true, - underStatusBar: false, - underAppBar: false, - //offsetX: -180, - //offsetY: 50, - duration: const Duration(milliseconds: 200), - onShowStart: (pop) {}, - onShowFinish: (pop) {}, - onDismissStart: (pop) {}, - onDismissFinish: (pop) {}, - onClickOut: (pop) {}, - onClickBack: (pop) {}, - childFun: (pop) { - final SignatureController controller = SignatureController(); +showSignaturePopup(BuildContext context, TaskInfo taskInfo, Function() onFinished) async { + await showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + contentPadding: EdgeInsets.zero, + shadowColor: Colors.transparent, + backgroundColor: Colors.white, + content: StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + final SignatureController controller = SignatureController(); - var popupHeight = MediaQuery.of(context).size.height * 0.85; - var popupWidth = MediaQuery.of(context).size.width * 0.85; + var popupHeight = MediaQuery.of(context).size.height * 0.85; + var popupWidth = MediaQuery.of(context).size.width * 0.85; - return SizedBox( - key: GlobalKey(), - height: popupHeight, - width: popupWidth, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - border: Border.all( - color: Colors.grey, - width: 0.5, - ), - ), - child: Padding( - padding: const EdgeInsets.all(20.0), - child: Column( - children: [ - Text(taskInfo.task.topic), - const SizedBox(height: 20), - Expanded( - child: Signature( - controller: controller, - width: 500, - height: 200, - backgroundColor: Colors.lightBlueAccent, - ), - ), - getDefaultButton('Übernehmen', buttonHeight: 50, () => { - onFinished() - }) - ], - ), - ), - ) - ); - }, - ); + return SizedBox( + key: GlobalKey(), + height: popupHeight, + width: popupWidth, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + border: Border.all( + color: Colors.grey, + width: 0.5, + ), + ), + child: Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + children: [ + Text(taskInfo.task.topic), + const SizedBox(height: 20), + Expanded( + child: Signature( + controller: controller, + width: 500, + height: 200, + backgroundColor: Colors.lightBlueAccent, + ), + ), + getDefaultButton('Übernehmen', buttonHeight: 50, () => {Navigator.of(context).pop(), onFinished()}) + ], + ), + ), + )); + }, + )); + }); } - -/* - - */ \ No newline at end of file