diff --git a/lib/content_views/task_list_page.dart b/lib/content_views/task_list_page.dart index b299892..818fe46 100644 --- a/lib/content_views/task_list_page.dart +++ b/lib/content_views/task_list_page.dart @@ -284,15 +284,13 @@ class _TaskListPageState extends State { } _processTakePhotos(TaskInfo taskInfo) { - _popup = showTakePhotosPopup(context, taskInfo, () { + showTakePhotosPopup(context, taskInfo, () { taskInfo.additionalText = "Fotos aufgenommen"; taskInfo.completed = true; setState(() {}); _finishTaskProcessing(taskInfo); - - _popup.dismiss(context); }); } diff --git a/lib/popups/tasks_popups/take_photos_popup.dart b/lib/popups/tasks_popups/take_photos_popup.dart index a73ec42..2f3d7da 100644 --- a/lib/popups/tasks_popups/take_photos_popup.dart +++ b/lib/popups/tasks_popups/take_photos_popup.dart @@ -1,85 +1,49 @@ import 'package:carousel_slider/carousel_slider.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:kumi_popup_window/kumi_popup_window.dart'; import 'package:stadtbote/model/task_info.dart'; import 'package:stadtbote/tools/util.dart'; -KumiPopupWindow showTakePhotosPopup(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: true, - 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) { - List imageList = []; - List imageWidgetsList = []; +Future showTakePhotosPopup(BuildContext context, TaskInfo taskInfo, Function() onFinished) async { + List imageDataList = []; + List imageWidgetsList = []; - ValueNotifier> imageWidgetsListNotifier = ValueNotifier>([]); + ValueNotifier> imageWidgetsListNotifier = ValueNotifier>([]); - void capturePhoto() async { - var photo = await Util.capturePhoto(); + 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) { + void capturePhoto() async { + var photo = await Util.capturePhoto(); - if (photo != null) { - var imageData = await photo.readAsBytes(); - photo.delete(); + if (photo != null) { + var imageData = await photo.readAsBytes(); + photo.delete(); - imageList.add(imageData); + imageDataList.add(imageData); - imageWidgetsList.clear(); - for(var image in imageList) { - imageWidgetsList.add(GestureDetector( - onTap: () { - }, - child: Image.memory(image), - )); - } + imageWidgetsList.add(GestureDetector( + onTap: () {}, + child: Image.memory(imageData), + )); - imageWidgetsListNotifier.value = imageWidgetsList; - imageWidgetsListNotifier.notifyListeners(); - } - } + imageWidgetsListNotifier.value = imageWidgetsList; - return SizedBox( - key: GlobalKey(), - height: 530, - width: MediaQuery.of(context).size.width * 0.8, - child: Container( - height: 100, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - border: Border.all( - color: Colors.grey, - width: 0.5, - ), - ), - child: Padding( - padding: const EdgeInsets.all(35.0), - child: Column( - children: [ - const Text('Aufgenommene Fotos'), - const SizedBox(height: 20), - Container( + setState(() {}); + } + } + + return SizedBox( + key: GlobalKey(), + height: 545, + width: MediaQuery.of(context).size.width * 0.8, + child: Container( + height: 100, decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), color: Colors.white, @@ -88,27 +52,50 @@ KumiPopupWindow showTakePhotosPopup(BuildContext context, TaskInfo taskInfo, Fun width: 0.5, ), ), - height: 300, - child: ValueListenableBuilder>( - valueListenable: imageWidgetsListNotifier, - builder: (context, value, child) { - return CarouselSlider( - options: CarouselOptions( - disableCenter: false, - enableInfiniteScroll: false, + child: Padding( + padding: const EdgeInsets.all(35.0), + child: Column( + children: [ + const Text('Aufgenommene Fotos'), + const SizedBox(height: 20), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + border: Border.all( + color: Colors.grey, + width: 0.5, + ), ), - items: imageWidgetsList.toList() - ); - }, + height: 300, + child: ValueListenableBuilder>( + valueListenable: imageWidgetsListNotifier, + builder: (context, value, child) { + return CarouselSlider( + options: CarouselOptions( + disableCenter: false, + enableInfiniteScroll: false, + ), + items: imageWidgetsList.toList()); + }, + ), + ), + const SizedBox(height: 20), + Visibility(visible: imageDataList.length < taskInfo.task.max!, child: getDefaultButton('Hinzufügen', buttonHeight: 50, () => {capturePhoto()})), + const SizedBox(height: 12), + getDefaultButton( + 'Übernehmen', + buttonHeight: 50, + () => { + if (imageDataList.length == taskInfo.task.min! && imageDataList.length <= taskInfo.task.max!) + {Navigator.of(context).pop(), onFinished()} + else + {showAlertDialog(context, 'Fehler', 'Sie müssen mindestens ${taskInfo.task.min} Foto(s) aufnehmen')} + }) + ], + ), ), - ), - const SizedBox(height: 20), - getDefaultButton('Hinzufügen', buttonHeight: 50, () => {capturePhoto()}), - getDefaultButton('Übernehmen', buttonHeight: 50, () => {onFinished()}) - ], - ), - ), - )); - }, - ); + )); + })); + }); }