Erweiterungen

This commit is contained in:
Sven committed 2024-02-14 11:21:22 +01:00
1 parent 31fe4c5a06
commit 98581c9a39
13 files changed
+2792 -996

No files matched your search

+163 -19
View File
@@ -1,9 +1,20 @@
import 'package:flutter/material.dart';
import 'package:isar/isar.dart';
import 'package:stadtbote/content_views/utils/content_view_widget.dart';
import 'package:stadtbote/content_views/utils/header_info.dart';
import 'package:stadtbote/model/ranking.dart';
import 'package:stadtbote/popups/tasks_popups/zip_popup.dart';
import 'package:stadtbote/protocoll_messages/zip_message.dart';
import 'package:stadtbote/tools/mqtt_core.dart';
import '../main.dart';
import '../tools/util.dart';
enum ModeEnum {
set,
request
}
class ApproachAreaPage extends ContentViewWidget {
const ApproachAreaPage({super.key});
@@ -14,7 +25,7 @@ class ApproachAreaPage extends ContentViewWidget {
Future<HeaderInfo> getHeaderInfo(BuildContext context) async {
return HeaderInfo(
titleWidget: const Text(
'Angenommene Aufträge',
'Anfahrtsbereich',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
@@ -30,14 +41,14 @@ class ApproachAreaPage extends ContentViewWidget {
}
class _ApproachAreaPageState extends State<ApproachAreaPage> {
//late List<Job> _jobs;
late Ranking? _ranking;
late bool _initCompleted = false;
@override
void initState() {
Future.delayed(const Duration(seconds: 0), () async {
//_jobs = await MyApp.isarInstance.jobs.filter().stateEqualTo(1).findAll();
_ranking = await MyApp.isarInstance.rankings.where().findFirst();
_initCompleted = true;
@@ -53,25 +64,158 @@ class _ApproachAreaPageState extends State<ApproachAreaPage> {
return Util.getWaitWidget(context);
}
return const SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
SizedBox(width: 80, child: Text('Row 1')),
SizedBox(width: 80, child: Text('Row 2')),
SizedBox(width: 80, child: Text('Row 3')),
SizedBox(width: 80, child: Text('Row 4')),
SizedBox(width: 80, child: Text('Row 5')),
SizedBox(width: 80, child: Text('Row 6')),
],
return Padding(
padding: const EdgeInsets.all(8.0),
child: InteractiveViewer(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: _fillColumns()),
),
),
),
);
}
/*void _clicked(Job job) {
MessageService().publish<ContentViewWidget>(Constants.messageTopicPushContentView, arguments: TourListPage(job: job));
}*/
List<Widget> _fillColumns() {
List<Widget> columns = [];
if (_ranking != null) {
for (int i = 0; i < _ranking!.ranks.length; i++) {
var rank = _ranking!.ranks[i];
List<Widget> entries = [];
entries.add(
GestureDetector(
onTap: ()=> {
if (i == 0) {
showZipPopup(context, 'ACHTUNG: Wenn Sie Ihre PLZ ändern, verlieren Sie Ihr Ranking!\n', 'Freimelden', (zip) => {_sendZip(rank, zip, ModeEnum.set)}),
} else {
showZipPopup(context, 'ACHTUNG: Wenn Sie Ihre PLZ ändern, verlieren Sie Ihr Ranking!\n', 'OK', (zip) => {_sendZip(rank, zip, ModeEnum.request)}),
}
},
child: Container(
padding: const EdgeInsets.all(4),
margin: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: i == 0 ? Colors.lightGreen : Colors.white,
border: Border.all(
color: Colors.grey,
width: 0.5,
),
),
width: 85,
height: 60,
child: Column(children: [
Text(
rank.zip,
style: const TextStyle(fontSize: 20),
),
Text(
rank.area,
)
]
)
),
),
);
for (int j = 0; j < rank.vehicles.length; j++) {
var vehicle = rank.vehicles[j];
var imageFilename = vehicle.self == true ? "assets/mein_${mapVehicleTypeToImageName(vehicle.type)}" : "assets/${mapVehicleTypeToImageName(vehicle.type)}";
entries.add(Container(
padding: const EdgeInsets.all(4),
margin: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border.all(
color: Colors.grey,
width: 0.5,
),
),
width: 80,
height: 60,
child: Column(
children: [
Image.asset(imageFilename, width: 30, height: 30),
const SizedBox(width: 10),
Text(
mapVehicleTypeToText(vehicle.type)
),
],
),
));
}
columns.add(Align(
alignment: Alignment.topLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: entries,
),
));
}
}
return columns;
}
_sendZip(Rank rank, String zip, ModeEnum mode) {
var zipMessage = ZipMessage();
if (mode == ModeEnum.set) {
var position = MyApp.currentPosition;
zipMessage.setPos = ZipSetPos();
zipMessage.setPos!.zip = zip;
if (position != null) {
zipMessage.setPos!.track = ZipTrack();
zipMessage.setPos!.track.time = DateTime.now().toIso8601String();
zipMessage.setPos!.track.pos = ZipTrackPos();
zipMessage.setPos!.track.pos!.lat = position.latitude;
zipMessage.setPos!.track.pos!.long = position.longitude;
zipMessage.setPos!.track.pos!.acc = position.accuracy.toInt();
}
} else {
zipMessage.reqZip = ZipReqZip();
zipMessage.reqZip!.id = rank.id;
zipMessage.reqZip!.zip = zip;
}
MqttCore.instance.publishPayloadMessage("rank", zipMessage.toJson());
}
}
/*
private void SendMessage(int columnNumber, string zipNumber)
{
var payloadObject = new JObject();
if (columnNumber == 0)
{
var setPosObject = new JObject();
payloadObject.Add(new JProperty("set_pos", setPosObject));
setPosObject.Add(new JProperty("zip", zipNumber));
setPosObject.Add(new JProperty("track", CreateTrackObject()));
}
else
{
var regZipObject = new JObject();
payloadObject.Add(new JProperty("reg_zip", regZipObject));
regZipObject.Add(new JProperty("id", columnNumber));
regZipObject.Add(new JProperty("zip", zipNumber));
}
var json = payloadObject.ToString();
App.Core.SendJsonMessageAsync("rank", payloadObject);
}
*/