245 lines
7.6 KiB
Dart
245 lines
7.6 KiB
Dart
import 'package:dart_mq/dart_mq.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart' show DateFormat;
|
|
import 'package:stadtbote/content_views/tour_list_page.dart';
|
|
import 'package:stadtbote/content_views/utils/content_view_widget.dart';
|
|
import 'package:stadtbote/messages/pop_content_view_message.dart';
|
|
|
|
import '../main.dart';
|
|
import '../model/job.dart';
|
|
import '../objectbox.g.dart';
|
|
import '../tools/constants.dart';
|
|
import '../tools/util.dart';
|
|
|
|
class AcceptedJobsPage extends ContentViewWidget {
|
|
const AcceptedJobsPage({super.key});
|
|
|
|
@override
|
|
State<AcceptedJobsPage> createState() => _AcceptedJobsPageState();
|
|
|
|
@override
|
|
Future<Widget> getHeaderWidget(BuildContext context) async {
|
|
await Future.delayed(const Duration(microseconds: 0));
|
|
|
|
return _HeaderWidget();
|
|
}
|
|
}
|
|
|
|
class _AcceptedJobsPageState extends State<AcceptedJobsPage>
|
|
with ProducerMixin {
|
|
late List<Job> _jobs;
|
|
|
|
late bool _initCompleted = false;
|
|
|
|
@override
|
|
void initState() {
|
|
Future.delayed(const Duration(seconds: 0), () async {
|
|
final box = MyApp.objectBoxStore.box<Job>();
|
|
final query = box.query(Job_.state.equals(Constants.stateAccepted)).build();
|
|
_jobs = query.find();
|
|
query.close();
|
|
|
|
_jobs.sort((job1, job2) {
|
|
var date1 = DateTime.fromMillisecondsSinceEpoch(job1.ordertime * 1000, isUtc: true).millisecondsSinceEpoch;
|
|
var date2 = DateTime.fromMillisecondsSinceEpoch(job2.ordertime * 1000, isUtc: true).millisecondsSinceEpoch;
|
|
|
|
return date1 - date2;
|
|
});
|
|
|
|
_initCompleted = true;
|
|
|
|
setState(() {});
|
|
});
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!_initCompleted) {
|
|
return Util.getWaitWidget(context);
|
|
}
|
|
|
|
late List<Widget> jobWidgets = _createjobWidgets();
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Scrollbar(
|
|
thumbVisibility: true,
|
|
child: ListView(children: jobWidgets),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Widget> _createjobWidgets() {
|
|
List<Widget> jobWidgets = [];
|
|
|
|
for (var job in _jobs) {
|
|
var bottomText =
|
|
"${job.externalId}\n${job.tours[0].comp}\n${job.tours[0].street}\n${job.tours[0].city}";
|
|
if (job.rem.trim().isNotEmpty) {
|
|
bottomText += "\n\n${job.rem.trim()}";
|
|
}
|
|
|
|
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.fromMillisecondsSinceEpoch(job.ordertime * 1000, isUtc: true).toLocal())
|
|
.toString(),
|
|
style: TextStyle(
|
|
backgroundColor: isJobTooFarInFuture(job)
|
|
? Colors.red
|
|
: Colors.transparent),
|
|
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(
|
|
bottomText,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
],
|
|
),
|
|
)),
|
|
);
|
|
}
|
|
|
|
return jobWidgets;
|
|
}
|
|
|
|
void _clicked(Job job) async {
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPushContentView,
|
|
payload: TourListPage(job: job),
|
|
);
|
|
}
|
|
}
|
|
|
|
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 {
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPopContentView,
|
|
payload: 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 {
|
|
sendMessage(
|
|
routingKey: Constants.messageTopicPopContentView,
|
|
payload: 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,
|
|
"Angenommene Aufträge",
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 18,
|
|
color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|