From 4eef6fe17a48e535c902336fad4ea7aab1963ce1 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Fri, 9 Jun 2023 23:13:41 +0200 Subject: show qr --- lib/RoutingExample.dart | 3 +- lib/navigation/baseNavigation.dart | 103 +++++++++++++++++++----------- lib/pages/navigation_page.dart | 125 +++++++++++++++++++++++-------------- lib/route.dart | 4 +- pubspec.yaml | 3 + 5 files changed, 152 insertions(+), 86 deletions(-) diff --git a/lib/RoutingExample.dart b/lib/RoutingExample.dart index 23b0be3..2ab5193 100644 --- a/lib/RoutingExample.dart +++ b/lib/RoutingExample.dart @@ -284,7 +284,8 @@ class RoutingExample { postalcodeNumeric: item.postalCodeNumeric, postalcodeAlpha: item.postalCodeAlpha, houseNumberWithExtra: - item.houseNumber! + (item.houseNumberAddition ?? '')), + item.houseNumber! + (item.houseNumberAddition ?? ''), + pid: item.pid), ); _destinationCoords.add(destinationGeoCoordinates); diff --git a/lib/navigation/baseNavigation.dart b/lib/navigation/baseNavigation.dart index 1aed658..94b73ed 100644 --- a/lib/navigation/baseNavigation.dart +++ b/lib/navigation/baseNavigation.dart @@ -1,15 +1,20 @@ import 'dart:async'; +import 'dart:io'; +import 'dart:typed_data'; +import 'package:barcode_image/barcode_image.dart'; import 'package:flutter/material.dart'; +import 'package:image/image.dart' as img; +import 'package:side_sheet/side_sheet.dart'; import 'package:training_planner/events/NextStopLoadedEvent.dart'; import 'package:training_planner/events/StopCompletedEvent.dart'; import 'package:training_planner/main.dart'; - import '../route.dart' as DHLRoute; import 'package:training_planner/services/iblacklist_provider_service.dart'; class DestinationPin { final int numberOfParcels; final int sequenceNumber; + final String? pid; final DHLCoordinates coords; final String? postalcodeNumeric; final String? postalcodeAlpha; @@ -24,7 +29,8 @@ class DestinationPin { required this.isDoublePlannedAddress, required this.postalcodeNumeric, required this.postalcodeAlpha, - required this.houseNumberWithExtra}); + required this.houseNumberWithExtra, + required this.pid}); } class DHLCoordinates { @@ -93,6 +99,19 @@ abstract class BaseNavigationState extends State { }); } + buildBarcode(String pid) { + // Create an image + final image = img.Image((MediaQuery.of(context).size.width * 1).round(), + (MediaQuery.of(context).size.height * 1).round()); + + // Fill it with a solid color (white) + img.fill(image, 0xFFFFFF); + + // Draw the barcode + drawBarcode(image, Barcode.pdf417(), pid); + return Uint8List.fromList(img.encodePng(image)); + } + void flyTo(DHLCoordinates coords); void changeZoom(double newVal); Future addRoute(DHLRoute.Route route); @@ -114,42 +133,51 @@ abstract class BaseNavigationState extends State { width: 2), ), child: GestureDetector( + onTap: () async { + SideSheet.right( + body: Transform.rotate( + angle: -3.1415 / 2, + child: Container( + child: Image.memory(buildBarcode(pin.pid ?? ''))), + ), + context: context); + }, child: Row( - children: [ - Container( - padding: EdgeInsets.all(3), - decoration: BoxDecoration( - color: Color.fromARGB(255, 0, 0, 0), - borderRadius: BorderRadius.circular(10), - shape: BoxShape.rectangle, - ), - child: RichText( - text: TextSpan(children: [ - TextSpan( - text: pin.sequenceNumber.toString(), - style: TextStyle( - fontSize: 20.0, - color: Color.fromARGB(255, 255, 255, 255)), + children: [ + Container( + padding: EdgeInsets.all(3), + decoration: BoxDecoration( + color: Color.fromARGB(255, 0, 0, 0), + borderRadius: BorderRadius.circular(10), + shape: BoxShape.rectangle, + ), + child: RichText( + text: TextSpan(children: [ + TextSpan( + text: pin.sequenceNumber.toString(), + style: TextStyle( + fontSize: 20.0, + color: Color.fromARGB(255, 255, 255, 255)), + ), + if (pin.numberOfParcels > 1) + TextSpan( + text: ' ' + pin.numberOfParcels.toString(), + style: TextStyle( + fontSize: 12.0, + color: Color.fromARGB(255, 255, 255, 255)), + ) + ]), + ), + ), + Container( + padding: EdgeInsets.all(3), + child: Text( + pin.houseNumberWithExtra ?? 'Zie pakket', + style: TextStyle(fontSize: 20.0), ), - if (pin.numberOfParcels > 1) - TextSpan( - text: ' ' + pin.numberOfParcels.toString(), - style: TextStyle( - fontSize: 12.0, - color: Color.fromARGB(255, 255, 255, 255)), - ) - ]), - ), - ), - Container( - padding: EdgeInsets.all(3), - child: Text( - pin.houseNumberWithExtra ?? 'Zie pakket', - style: TextStyle(fontSize: 20.0), - ), - ), - ], - )), + ), + ], + )), ); } @@ -288,7 +316,8 @@ abstract class BaseNavigationState extends State { postalcodeNumeric: item.postalCodeNumeric, postalcodeAlpha: item.postalCodeAlpha, houseNumberWithExtra: - item.houseNumber! + (item.houseNumberAddition ?? '')), + item.houseNumber! + (item.houseNumberAddition ?? ''), + pid: item.pid!), ); widget.destinationCoords.add(destinationGeoCoordinates); diff --git a/lib/pages/navigation_page.dart b/lib/pages/navigation_page.dart index 9fcc9ae..0f8b454 100644 --- a/lib/pages/navigation_page.dart +++ b/lib/pages/navigation_page.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:auto_orientation/auto_orientation.dart'; import 'package:flutter/services.dart'; +import 'package:side_sheet/side_sheet.dart'; import 'package:training_planner/navigation/HERENavigation.dart'; import 'package:training_planner/navigation/baseNavigation.dart'; import 'package:training_planner/navigation/openstreetmapNavigation.dart'; @@ -69,6 +70,7 @@ class _NavigationPageState extends State { SystemChrome.setPreferredOrientations([]); Wakelock.enable(); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); AutoOrientation.portraitDownMode(); _handleLocationPermission(); @@ -106,65 +108,94 @@ class _NavigationPageState extends State { eventBus.fire(StopIncompletedEvent()); } + Future showExitPopup() async { + return await showDialog( + //show confirm dialogue + //the return value will be from "Yes" or "No" options + context: context, + builder: (context) => AlertDialog( + title: Text('Terug'), + content: Text('Terug naar vorig scherm?'), + actions: [ + ElevatedButton( + onPressed: () => Navigator.of(context).pop(false), + //return false when click on "NO" + child: Text('Nee'), + ), + ElevatedButton( + onPressed: () => Navigator.of(context).pop(true), + //return true when click on "Yes" + child: Text('Ja'), + ), + ], + ), + ) ?? + false; //if showDialouge had returned null, then return false + } + @override Widget build(BuildContext context) { if (navigation == null) { navigation = HERENavigation(route: widget.route); } - return Scaffold( - floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - InkWell( - splashColor: Colors.blue, - onLongPress: () => _mockStopInComplete(), - child: FloatingActionButton( - onPressed: () => _mockStopComplete(), - child: Icon(Icons.check_circle), + return WillPopScope( + onWillPop: showExitPopup, //call function on back button press + child: Scaffold( + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + floatingActionButton: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + InkWell( + splashColor: Colors.blue, + onLongPress: () => _mockStopInComplete(), + child: FloatingActionButton( + onPressed: () => _mockStopComplete(), + child: Icon(Icons.check_circle), + ), ), - ), - Visibility( - visible: navigation == null ? false : navigation!.isLookingAround, - child: FloatingActionButton( - backgroundColor: Colors.green, - child: const Icon(Icons.center_focus_strong), - onPressed: () => { - changeIsLookingAround(false), - eventBus.fire(FlyToEvent(navigation!.lastPosition)) - }, + Visibility( + visible: + navigation == null ? false : navigation!.isLookingAround, + child: FloatingActionButton( + backgroundColor: Colors.green, + child: const Icon(Icons.center_focus_strong), + onPressed: () => { + changeIsLookingAround(false), + eventBus.fire(FlyToEvent(navigation!.lastPosition)) + }, + ), + ), + Padding(padding: EdgeInsets.all(5)), + FloatingActionButton( + onPressed: () => _zoomOut(), + child: Icon(Icons.zoom_out), + ), + Padding(padding: EdgeInsets.all(2)), + FloatingActionButton( + onPressed: () => _zoomIn(), + child: Icon(Icons.zoom_in), ), + ], + ), + ), + body: Column( + children: [ + _createNextDropInfoWidget(), + Container( + decoration: BoxDecoration(color: Colors.black), + height: 2, ), - Padding(padding: EdgeInsets.all(5)), - FloatingActionButton( - onPressed: () => _zoomOut(), - child: Icon(Icons.zoom_out), + Expanded( + child: Stack( + children: [navigation!], + ), ), - Padding(padding: EdgeInsets.all(2)), - FloatingActionButton( - onPressed: () => _zoomIn(), - child: Icon(Icons.zoom_in), - ) ], ), ), - body: Column( - children: [ - _createNextDropInfoWidget(), - Container( - decoration: BoxDecoration(color: Colors.black), - height: 2, - ), - Expanded( - child: Stack( - children: [navigation!], - ), - ), - ], - ), ); } @@ -251,6 +282,8 @@ class _NavigationPageState extends State { taskLoadedEvent?.cancel(); Wakelock.disable(); AutoOrientation.portraitUpMode(); + SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, + overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]); SystemChrome.setPreferredOrientations( [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); super.dispose(); diff --git a/lib/route.dart b/lib/route.dart index e622c12..4531f9b 100644 --- a/lib/route.dart +++ b/lib/route.dart @@ -137,8 +137,8 @@ class Task { String? beginDeliveryPickupWindow; String? endDeliveryPickupWindow; String? deliveryInstruction; - Null? parcelDeliveryRemark; - Null? courierRemark; + dynamic? parcelDeliveryRemark; + dynamic? courierRemark; String? serviceType; bool? servicepointParcel; String? servicepointid; diff --git a/pubspec.yaml b/pubspec.yaml index a66e311..3ceb50a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -53,6 +53,9 @@ dependencies: flutter_map: ^3.1.0 permission_handler: ^10.3.0 flutter_archive: ^5.0.0 + side_sheet: ^1.0.4 + barcode: ^2.2.4 + barcode_image: ^2.0.2 dev_dependencies: flutter_test: -- cgit v1.2.3-70-g09d2