232 lines
7.3 KiB
Dart
232 lines
7.3 KiB
Dart
import 'package:dart_mq/dart_mq.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:isar/isar.dart';
|
|
import 'package:stadtbote/content_views/tour_list_page.dart';
|
|
import 'package:stadtbote/content_views/utils/content_view_widget.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:stadtbote/messages/pop_content_view_message.dart';
|
|
import 'package:stadtbote/tools/message_service.dart';
|
|
|
|
import '../main.dart';
|
|
import '../model/job.dart';
|
|
import '../tools/constants.dart';
|
|
import '../tools/util.dart';
|
|
|
|
class FinishedJobsPage extends ContentViewWidget {
|
|
const FinishedJobsPage({super.key});
|
|
|
|
@override
|
|
State<FinishedJobsPage> createState() => _FinishedJobsPageState();
|
|
|
|
@override
|
|
Future<Widget> getHeaderWidget(BuildContext context) async {
|
|
await Future.delayed(const Duration(microseconds: 0));
|
|
|
|
return _HeaderWidget();
|
|
}
|
|
}
|
|
|
|
class _FinishedJobsPageState extends State<FinishedJobsPage> with ProducerMixin {
|
|
late List<Job> _jobs;
|
|
|
|
late bool _initCompleted = false;
|
|
|
|
@override
|
|
void initState() {
|
|
Future.delayed(const Duration(seconds: 0), () async {
|
|
_jobs = await MyApp.isarInstance.jobs.filter().stateEqualTo(Constants.stateFinished).findAll();
|
|
|
|
_initCompleted = true;
|
|
|
|
setState(() {});
|
|
});
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!_initCompleted) {
|
|
return Util.getWaitWidget(context);
|
|
}
|
|
|
|
late List<Widget> jobWidgets = _createjobWidgets();
|
|
|
|
return ListView(
|
|
children: jobWidgets
|
|
);
|
|
}
|
|
|
|
List<Widget> _createjobWidgets() {
|
|
List<Widget> jobWidgets = [];
|
|
|
|
for (var job in _jobs) {
|
|
jobWidgets.add(
|
|
ListTile(
|
|
onTap: () {
|
|
_clicked(job);
|
|
},
|
|
title: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border.all(color: Colors.grey, width: 0.5),
|
|
borderRadius: const BorderRadius.all(Radius.circular(13))
|
|
),
|
|
padding: const EdgeInsets.all(15.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text(
|
|
DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime).toLocal()).toString(),
|
|
textAlign: TextAlign.left,
|
|
),
|
|
Text(
|
|
job.crFilter != null ? job.crFilter.toString() : "",
|
|
textAlign: TextAlign.left,
|
|
),
|
|
Row(
|
|
children: [
|
|
Image.asset("assets/${mapVehicleTypeToImageName(job.vhtId)}", width: 60, height: 60),
|
|
const SizedBox(width: 10),
|
|
Text(
|
|
mapVehicleTypeToText(job.vhtId)
|
|
),
|
|
],
|
|
),
|
|
Text(
|
|
job.id.toString(),
|
|
textAlign: TextAlign.left,
|
|
),
|
|
Text(
|
|
job.tours[0].comp,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
Text(
|
|
job.tours[0].street,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
Text(
|
|
job.tours[0].city,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
],
|
|
),
|
|
)
|
|
),
|
|
);
|
|
}
|
|
|
|
return jobWidgets;
|
|
}
|
|
|
|
void _clicked(Job job) async {
|
|
// TODO MESSAGING
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPushContentView,
|
|
payload: TourListPage(job: job, readOnly: true),
|
|
);
|
|
|
|
//await MessageService().publish<ContentViewWidget>(Constants.messageTopicPushContentView, arguments: TourListPage(job: job, readOnly: true,));
|
|
}
|
|
}
|
|
|
|
class _HeaderWidget extends StatefulWidget {
|
|
@override
|
|
State<_HeaderWidget> createState() => _HeaderWidgetState();
|
|
}
|
|
|
|
class _HeaderWidgetState extends State<_HeaderWidget> with ProducerMixin {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var cellWidth = (MediaQuery.of(context).size.width - 60 - 60 - 25) / 2;
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Visibility(
|
|
visible: true,
|
|
child: Container(
|
|
width: 60,
|
|
height: 60,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.white,
|
|
),
|
|
child: FittedBox(
|
|
child: GestureDetector(
|
|
onTap: () async {
|
|
// TODO MESSAGING
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPopContentView,
|
|
payload: PopContentViewMessage(count: 1),
|
|
);
|
|
|
|
//await MessageService().publish<PopContentViewMessage>(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1));
|
|
},
|
|
child: const CircleAvatar(
|
|
radius: 10,
|
|
backgroundColor: Constants.colorPrimary,
|
|
child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.arrow_back, size: 20.0, color: Colors.white)),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Visibility(
|
|
visible: false,
|
|
child: Container(
|
|
width: 60,
|
|
height: 60,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.red,
|
|
),
|
|
child: FittedBox(
|
|
child: GestureDetector(
|
|
onTap: () async {
|
|
// TODO MESSAGING
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPushContentView,
|
|
payload: PopContentViewMessage(count: 1),
|
|
);
|
|
|
|
//await MessageService().publish<PopContentViewMessage>(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 1));
|
|
},
|
|
child: const CircleAvatar(
|
|
backgroundColor: Constants.colorPrimary,
|
|
radius: 10,
|
|
child: Padding(padding: EdgeInsets.all(1.0), child: Icon(Icons.info_outline, size: 20.0, color: Colors.white))),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 100,
|
|
width: cellWidth * 2,
|
|
child: const Center(
|
|
child: Text(
|
|
textAlign: TextAlign.center,
|
|
"Erledigte Aufträge",
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|