From fcbf592d10199dbac80198dd8c2efb181f95165e Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Wed, 8 Feb 2023 20:08:23 +0100 Subject: blacklist --- lib/RoutingExample.dart | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'lib/RoutingExample.dart') diff --git a/lib/RoutingExample.dart b/lib/RoutingExample.dart index 910fe3e..ebe08b3 100644 --- a/lib/RoutingExample.dart +++ b/lib/RoutingExample.dart @@ -20,6 +20,7 @@ import 'package:training_planner/events/MapPanningEvent.dart'; import 'package:training_planner/events/NextStopLoadedEvent.dart'; import 'package:training_planner/events/StopCompletedEvent.dart'; import 'package:training_planner/pages/navigation_page.dart'; +import 'package:training_planner/services/iblacklist_provider_service.dart'; import 'route.dart' as DHLRoute; import 'main.dart'; @@ -30,11 +31,19 @@ typedef ShowDialogFunction = void Function(String title, String message); class DestinationPin { final String text; final GeoCoordinates? coords; + final String? postalcodeNumeric; + final String? postalcodeAlpha; + final String? houseNumberWithExtra; WidgetPin? pin; bool isDoublePlannedAddress; DestinationPin( - {this.text = '', this.coords, required this.isDoublePlannedAddress}); + {this.text = '', + this.coords, + required this.isDoublePlannedAddress, + required this.postalcodeNumeric, + required this.postalcodeAlpha, + required this.houseNumberWithExtra}); } class ActiveTask { @@ -76,6 +85,8 @@ class RoutingExample { late SearchOptions _searchOptions; late MapMarker mapMarker; + List blacklist = []; + Future _loadFileAsUint8List(String assetPathToFile) async { // The path refers to the assets directory as specified in pubspec.yaml. ByteData fileData = await rootBundle.load(assetPathToFile); @@ -131,6 +142,8 @@ class RoutingExample { updateHighlightedRouteSections(); eventBus.fire(NextStopLoadedEvent()); }); + + blacklistProvider.getBlacklist().then((value) => {blacklist = value}); } void destroy() { @@ -189,6 +202,7 @@ class RoutingExample { padding: EdgeInsets.all(2), decoration: BoxDecoration( color: backgroundColor, + borderRadius: BorderRadius.circular(10), shape: BoxShape.rectangle, border: Border.all( color: isDoublePlannedAddress @@ -273,7 +287,11 @@ class RoutingExample { ? item.houseNumberAddition! : ''), coords: destinationGeoCoordinates, - isDoublePlannedAddress: false), + isDoublePlannedAddress: false, + postalcodeNumeric: item.postalCodeNumeric, + postalcodeAlpha: item.postalCodeAlpha, + houseNumberWithExtra: + item.houseNumber! + (item.houseNumberAddition ?? '')), ); _destinationCoords.add(destinationGeoCoordinates); @@ -354,6 +372,24 @@ class RoutingExample { } } + bool destinationPinIsInBlacklist(DestinationPin pin) { + try { + for (int i = 0; i < blacklist.length; i++) { + if (pin.postalcodeNumeric == blacklist[i].postalcodeNumeric && + pin.postalcodeAlpha!.toLowerCase() == + blacklist[i].postalcodeAplha && + pin.houseNumberWithExtra!.toLowerCase() == + (blacklist[i].houseNumber.toString() + + blacklist[i].houseNumberExtra.toLowerCase())) { + return true; + } + } + return false; + } catch (e) { + return false; + } + } + void updateHighlightedRouteSections() { // Show the next 20 parcel pins, to let the delivery driver decide on possible detours. int maxPins = 300; @@ -391,6 +427,15 @@ class RoutingExample { widgetPin?.anchor = Anchor2D.withHorizontalAndVertical(0.5, 0.5); pin.pin = widgetPin; } + + if (destinationPinIsInBlacklist(_parcelNumberPins[i])) { + var widgetPin = hereMapController.pinWidget( + _createWidget(pin.text, ui.Color.fromARGB(255, 255, 0, 234), + isDoublePlannedAddress: pin.isDoublePlannedAddress), + _destinationCoords[i]); + widgetPin?.anchor = Anchor2D.withHorizontalAndVertical(0.5, 0.5); + pin.pin = widgetPin; + } } // Show the next 5 sections as to not clutter the screen. -- cgit v1.2.3-70-g09d2