205 lines
6.1 KiB
Dart
205 lines
6.1 KiB
Dart
import 'dart:convert';
|
|
|
|
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/main.dart';
|
|
import 'package:stadtbote/model/rank.dart';
|
|
import 'package:stadtbote/popups/tasks_popups/zip_popup.dart';
|
|
import 'package:stadtbote/protocoll_messages/zip_message.dart';
|
|
import 'package:stadtbote/tools/constants.dart';
|
|
import 'package:stadtbote/tools/message_service.dart';
|
|
import 'package:stadtbote/tools/mqtt_core.dart';
|
|
|
|
import '../tools/util.dart';
|
|
|
|
class ApproachAreaPage extends ContentViewWidget {
|
|
const ApproachAreaPage({super.key});
|
|
|
|
@override
|
|
State<ApproachAreaPage> createState() => _ApproachAreaPageState();
|
|
|
|
@override
|
|
Future<HeaderInfo> getHeaderInfo(BuildContext context) async {
|
|
return HeaderInfo(
|
|
titleWidget: const Text(
|
|
'Anfahrtsbereich',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 20.0,
|
|
),
|
|
),
|
|
rightButtonEnabled: true,
|
|
rightButtonVisible: true,
|
|
rightButtonImage: Util.fetchFutureIcon(const Icon(Icons.help_outline, size: 20.0, color: Colors.white)),
|
|
rightButtonOnPressed: () async {
|
|
await Util.startBrowser('https://app.assecutor.de/help/sb/app/context/001/index.html');
|
|
});
|
|
}
|
|
}
|
|
|
|
class _ApproachAreaPageState extends State<ApproachAreaPage> {
|
|
late List<Rank>? _ranking;
|
|
|
|
late bool _initCompleted = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
Future.delayed(const Duration(seconds: 0), () async {
|
|
_ranking = await MyApp.isarInstance.ranks.where().findAll();
|
|
|
|
_initCompleted = true;
|
|
|
|
_sendZip(Rank(), "24893");
|
|
|
|
setState(() {});
|
|
});
|
|
|
|
_initMessages();
|
|
}
|
|
|
|
@override
|
|
void deactivate() {
|
|
super.deactivate();
|
|
|
|
MessageService().unsubscribe(Constants.messageTopicRankingUpdated, this);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!_initCompleted) {
|
|
return Util.getWaitWidget(context);
|
|
}
|
|
|
|
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()),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Widget> _fillColumns() {
|
|
List<Widget> columns = [];
|
|
|
|
if (_ranking != null) {
|
|
for (int i = 0; i < _ranking!.length; i++) {
|
|
var rank = _ranking![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)}),
|
|
}
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.all(4),
|
|
margin: const EdgeInsets.all(2),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
color: i == 0 ? Constants.colorPrimary : Colors.white,
|
|
border: Border.all(
|
|
color: Colors.grey,
|
|
width: 0.5,
|
|
),
|
|
),
|
|
width: 85,
|
|
height: 60,
|
|
child: Column(children: [
|
|
Text(
|
|
rank.zip,
|
|
style: TextStyle(fontSize: 20, color: (i == 0 ? Colors.white : Colors.black)),
|
|
),
|
|
Text(
|
|
rank.area,
|
|
style: TextStyle(fontSize: 13, color: (i == 0 ? Colors.white : Colors.black)),
|
|
)
|
|
]
|
|
)
|
|
),
|
|
),
|
|
);
|
|
|
|
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) {
|
|
var position = MyApp.currentPosition;
|
|
|
|
var setPosMessage = ZipSetPos();
|
|
setPosMessage.zip = zip;
|
|
|
|
if (position != null) {
|
|
setPosMessage.track = ZipTrack();
|
|
setPosMessage.track!.time = DateTime.now().toIso8601String();
|
|
setPosMessage.track!.pos = ZipTrackPos();
|
|
setPosMessage.track!.pos!.lat = position.latitude;
|
|
setPosMessage.track!.pos!.long = position.longitude;
|
|
setPosMessage.track!.pos!.acc = position.accuracy.toInt();
|
|
}
|
|
|
|
var json = jsonEncode(setPosMessage.toJson());
|
|
Util.logInfo(json);
|
|
|
|
MqttCore.instance.publishMessage("set_zip", jsonEncode(setPosMessage.toJson()));
|
|
}
|
|
|
|
_initMessages() {
|
|
/*MessageService().subscribe<RankingUpdated>(Constants.messageTopicRankingUpdated, this, (rankingUpdateMessage) async {
|
|
_ranking = await MyApp.isarInstance.rankings.where().findFirst();
|
|
|
|
setState(() {});
|
|
});*/
|
|
}
|
|
} |