import 'package:flutter/material.dart'; import 'package:isar/isar.dart'; import 'package:kumi_popup_window/kumi_popup_window.dart'; import 'package:stadtbote/content_views/utils/content_view_widget.dart'; import 'package:stadtbote/content_views/utils/header_info.dart'; import 'package:stadtbote/model/job_tour.dart'; import 'package:stadtbote/popups/tasks_popups/arrived_popup.dart'; import 'package:stadtbote/popups/tasks_popups/commision_number_popup.dart'; import 'package:stadtbote/popups/tasks_popups/receipt_giver_popup.dart'; import 'package:stadtbote/popups/tasks_popups/scan_barcodes_popup.dart'; import 'package:stadtbote/popups/tasks_popups/station_notice_popup.dart'; import 'package:stadtbote/popups/tasks_popups/take_photos_popup.dart'; import '../main.dart'; import '../model/task_info.dart'; import '../tools/util.dart'; class TaskListPage extends ContentViewWidget { const TaskListPage({super.key, required this.tour}); final JobTour tour; @override State createState() => _TaskListPageState(); @override Future getHeaderInfo(BuildContext context) async { return HeaderInfo( titleWidget: const Text( 'Liste der Aufgaben', style: TextStyle( color: Colors.white, fontSize: 24.0, ), ), rightButtonEnabled: false, rightButtonVisible: false, rightButtonImage: null, rightButtonOnPressed: () async { //BroadcastReceiver().publish(Constants.messageTopicPushContentView, arguments: EmployeeEditProfileWidget()); }); } } class _TaskListPageState extends State { late bool _initCompleted = false; late List _taskList; late KumiPopupWindow _popup; @override void initState() { Future.delayed(const Duration(seconds: 0), () async { _taskList = await _fetchTaskList(); _initCompleted = true; setState(() {}); }); super.initState(); } @override Widget build(BuildContext context) { if (!_initCompleted) { return Util.getWaitWidget(context); } var steps = _initSteps(); return Padding( padding: const EdgeInsets.all(8.0), child: SingleChildScrollView( scrollDirection: Axis.vertical, padding: const EdgeInsets.all(0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: steps, ), ), ); } List _initSteps() { List steps = []; for (int i=0; i<_taskList.length; i++) { var taskInfo = _taskList[i]; steps.add( ListTile( minVerticalPadding: 0, title: Container( padding: const EdgeInsets.all(0), height: 60, child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Stack( children: [ Positioned( left: 16.5, top: i == 0 ? 5 : 0, child: Container( height: i == widget.tour.tasks.length - 1 ? 1: 60, width: 6, color: Colors.green ), ), Column( children: [ Container( width: 40, height: 40, decoration: const BoxDecoration( shape: BoxShape.circle, color: Colors.grey, ), child: const Icon(Icons.check, size: 30.0, color: Colors.white), ), ], ), ], ), const SizedBox(width: 20), Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( taskInfo.task.topic, textAlign: TextAlign.left, style: const TextStyle( color: Colors.blue, fontSize: 15.0, ), ), const SizedBox(height: 5), Text( taskInfo.additionalText ?? 'Additonal text', textAlign: TextAlign.left, style: const TextStyle( color: Colors.blue, fontSize: 12.0, ), ), ], ), ], ), ), onTap: () { _processTask(taskInfo); }, ), ); } return steps; } Future> _fetchTaskList() async { List taskList = []; for(var task in widget.tour.tasks) { var taskInfo = await MyApp.isarInstance.taskInfos.filter().sIdEqualTo(task.sId).findFirst(); taskInfo ??= TaskInfo(); taskInfo.task = task; taskInfo.answer = null; taskInfo.additionalText = null; taskList.add(taskInfo); } return taskList; } void _processTask(TaskInfo taskInfo) { switch(taskInfo.task.type) { case 3: _processTaskArrivedOrFinished(taskInfo); break; case 4: _processTakePhotos(taskInfo); break; case 5: _processScanBarcodes(taskInfo); break; case 7: _processReceiptGiver(taskInfo); break; case 8: _processStationNotice(taskInfo); break; case 9: _processCommissionNumber(taskInfo); break; } } void _processTaskArrivedOrFinished(TaskInfo taskInfo) { _popup = showTaskArrivedPopup(context, taskInfo, () => { _popup.dismiss(context), }); } void _processCommissionNumber(TaskInfo taskInfo) { _popup = showCommisionNumberPopup(context, taskInfo, () => { _popup.dismiss(context), }); } void _processScanBarcodes(TaskInfo taskInfo) { _popup = showScanBarcodesPopup(context, taskInfo, () => { _popup.dismiss(context) }); } void _processTakePhotos(TaskInfo taskInfo) { _popup = showTakePhotosPopup(context, taskInfo, () => { _popup.dismiss(context) }); } void _processStationNotice(TaskInfo taskInfo) { _popup = showStationNoticePopup(context, taskInfo, () => { _popup.dismiss(context) }); } void _processReceiptGiver(TaskInfo taskInfo) { _popup = showReceiptGiverPopup(context, taskInfo, () => { _popup.dismiss(context) }); } }