diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/RoutingExample.dart | 1 | ||||
| -rw-r--r-- | lib/config/defaults.dart | 2 | ||||
| -rw-r--r-- | lib/main.dart | 2 | ||||
| -rw-r--r-- | lib/pages/all_routes_page.dart | 38 | ||||
| -rw-r--r-- | lib/pages/delivery_login_page.dart | 4 | ||||
| -rw-r--r-- | lib/pages/navigation_page.dart | 11 | ||||
| -rw-r--r-- | lib/services/authentication_service.dart | 16 | ||||
| -rw-r--r-- | lib/services/istoregear_api_service.dart | 1 | ||||
| -rw-r--r-- | lib/services/storegear_api_service.dart | 57 |
9 files changed, 93 insertions, 39 deletions
diff --git a/lib/RoutingExample.dart b/lib/RoutingExample.dart index 02c097a..00e0e9d 100644 --- a/lib/RoutingExample.dart +++ b/lib/RoutingExample.dart @@ -231,7 +231,6 @@ class RoutingExample { text: item.deliverySequenceNumber.toString(), coords: destinationGeoCoordinates)); _destinationCoords.add(destinationGeoCoordinates); - debugPrint(item.deliverySequenceNumber); int sequenceNumber = int.parse(item.deliverySequenceNumber!); int groupLastSequenceNumber = int.parse(item.deliverySequenceNumber!); diff --git a/lib/config/defaults.dart b/lib/config/defaults.dart index 9c3855f..58af533 100644 --- a/lib/config/defaults.dart +++ b/lib/config/defaults.dart @@ -1,4 +1,4 @@ -String program_version = '0.4'; +String program_version = '0.5'; bool debug_output = false; class ShiftType { diff --git a/lib/main.dart b/lib/main.dart index 64e7162..66ad081 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,7 +5,6 @@ import 'package:event_bus/event_bus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; -import 'package:training_planner/services/authentication_service.dart'; import 'package:training_planner/services/iroute_provider_service.dart'; import 'package:training_planner/services/ishift_provider_service.dart'; import 'package:training_planner/services/istoregear_api_service.dart'; @@ -56,7 +55,6 @@ void _initializeHERESDK() async { final IRouteProviderService routeProvider = MockRouteProviderService(); final IProgramProviderService shiftProvider = LocalShiftProviderService(); final LocalAuthentication localAuthService = LocalAuthentication(); -final AuthenticationService remoteAuthService = AuthenticationService(); final MessagingService messageService = MessagingService(); final SettingsService settingsService = SettingsService(); final IStoregearApiService apiService = StoregearApiService(); diff --git a/lib/pages/all_routes_page.dart b/lib/pages/all_routes_page.dart index 495fc49..a1173cf 100644 --- a/lib/pages/all_routes_page.dart +++ b/lib/pages/all_routes_page.dart @@ -4,7 +4,8 @@ import 'package:in_date_utils/in_date_utils.dart' as DateUtilities; import 'package:loading_animation_widget/loading_animation_widget.dart'; import 'package:training_planner/main.dart'; import 'package:training_planner/models/route_list.dart'; -import 'package:training_planner/route.dart'; +import 'package:training_planner/pages/navigation_page.dart'; +import 'package:training_planner/route.dart' as DHLRoute; import 'package:training_planner/shift.dart'; import 'package:training_planner/style/style.dart'; import 'package:training_planner/utils/date.dart'; @@ -29,7 +30,26 @@ class _AllRoutesPageState extends State<AllRoutesPage> { setState(() => {routeInfo = value}); }); } catch (e) { - debugPrint(e.toString()); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Route lijst kan niet worden geladen'))); + } + } + + _startRoute(String tripkey) async { + try { + DHLRoute.Route? route = await apiService.getRoute(tripkey); + + if (route == null) { + throw new Exception(); + } + + Navigator.push( + context, + MaterialPageRoute(builder: (context) => NavigationPage(route: route)), + ); + } catch (e) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Route kan niet worden geladen'))); } } @@ -41,7 +61,8 @@ class _AllRoutesPageState extends State<AllRoutesPage> { padding: const EdgeInsets.only(bottom: 8, left: 10, right: 10), child: Container( decoration: BoxDecoration( - color: Style.background, + color: Color.fromARGB(40, 0, 0, 0), + border: Border.all(color: Color.fromARGB(160, 0, 0, 0)), borderRadius: BorderRadius.all(Radius.circular(4))), child: Padding( padding: const EdgeInsets.all(8), @@ -62,8 +83,10 @@ class _AllRoutesPageState extends State<AllRoutesPage> { padding: EdgeInsets.all(0), ), ), - OutlinedButton( - onPressed: () {}, + ElevatedButton( + onPressed: () { + _startRoute(route.tripKey!); + }, child: Text('Bekijk'), ), ], @@ -121,6 +144,11 @@ class _AllRoutesPageState extends State<AllRoutesPage> { @override Widget build(BuildContext context) { return Scaffold( + appBar: AppBar( + title: const Text('Werkschema'), + backgroundColor: Style.background, + foregroundColor: Style.titleColor, + ), body: Container( color: Colors.white, child: ShaderMask( diff --git a/lib/pages/delivery_login_page.dart b/lib/pages/delivery_login_page.dart index 15ab4b3..2ce6524 100644 --- a/lib/pages/delivery_login_page.dart +++ b/lib/pages/delivery_login_page.dart @@ -28,8 +28,8 @@ class _DeliveryLoginPageState extends State<DeliveryLoginPage> { initState() { super.initState(); - pnumberController.text = remoteAuthService.storedPNumber; - daycodeController.text = remoteAuthService.storedDaycode; + pnumberController.text = '639174'; + daycodeController.text = '424'; versionController.text = "1.12.3-prod"; } diff --git a/lib/pages/navigation_page.dart b/lib/pages/navigation_page.dart index 3ab40fd..f4042fc 100644 --- a/lib/pages/navigation_page.dart +++ b/lib/pages/navigation_page.dart @@ -1,5 +1,5 @@ import 'dart:async'; - +import 'package:training_planner/route.dart' as DHLRoute; import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; @@ -25,8 +25,9 @@ import 'package:here_sdk/mapview.dart'; class NavigationPage extends StatefulWidget { @override _NavigationPageState createState() => _NavigationPageState(); + final DHLRoute.Route route; - const NavigationPage({Key? key}) : super(key: key); + const NavigationPage({Key? key, required this.route}) : super(key: key); } class _NavigationPageState extends State<NavigationPage> { @@ -245,10 +246,8 @@ class _NavigationPageState extends State<NavigationPage> { (MapError? error) { if (error == null) { _routingExample = RoutingExample(hereMapController); - routeProvider.getRoute(0).then((value) { - _routingExample?.addRoute(value).then((value) { - eventBus.fire(RouteLoadedEvent(page: widget)); - }); + _routingExample?.addRoute(widget.route).then((value) { + eventBus.fire(RouteLoadedEvent(page: widget)); }); } else { print("Map scene not loaded. MapError: " + error.toString()); diff --git a/lib/services/authentication_service.dart b/lib/services/authentication_service.dart deleted file mode 100644 index ef9113e..0000000 --- a/lib/services/authentication_service.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:training_planner/services/istoregear_api_service.dart'; - -class AuthenticationService { - bool isAuthenticated = false; - String apiKey = ''; - String storedPNumber = '639174'; - String storedDaycode = '424'; - - Future<bool> authenticate(String username, String password) async { - isAuthenticated = true; - apiKey = 'test'; - storedPNumber = username; - storedDaycode = password; - return true; - } -} diff --git a/lib/services/istoregear_api_service.dart b/lib/services/istoregear_api_service.dart index adc07e0..d1a976e 100644 --- a/lib/services/istoregear_api_service.dart +++ b/lib/services/istoregear_api_service.dart @@ -6,4 +6,5 @@ import 'package:training_planner/route.dart'; abstract class IStoregearApiService { Future<LoginResponse> login(LoginRequest req); Future<RouteList> getRoutes(); + Future<Route?> getRoute(String tripkey); } diff --git a/lib/services/storegear_api_service.dart b/lib/services/storegear_api_service.dart index ecd0c94..109c17b 100644 --- a/lib/services/storegear_api_service.dart +++ b/lib/services/storegear_api_service.dart @@ -6,6 +6,8 @@ import 'package:training_planner/models/login_response.dart'; import 'package:training_planner/models/route_list.dart'; import 'package:training_planner/route.dart'; import 'package:training_planner/services/istoregear_api_service.dart'; +import 'package:training_planner/route.dart' as DHLRoute; +import 'package:training_planner/services/mock_route_provider_service.dart'; class StoregearApiService extends IStoregearApiService { String apiKey = ''; @@ -15,8 +17,7 @@ class StoregearApiService extends IStoregearApiService { final response = await http.post( Uri.parse('http://dhlapis.com/delivery/v1/users/login?env_type=PROD'), body: jsonEncode(req)); - debugPrint(jsonEncode(req)); - debugPrint(response.body); + if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. @@ -56,6 +57,29 @@ class StoregearApiService extends IStoregearApiService { "in_trip_scan_finished": "true", "eva_added": "true", "trip_start_request_sent": "true" + }, + { + "timeframe_key": "96870", + "trip_key": "18996871", + "trip_number": "10", + "trip_pda_status": "5", + "trip_pda_status_description": "Rit overgedragen", + "trip_sequence_number": "1", + "number_in_trip": "139", + "plate": "VND-37-B", + "damage_registration": true, + "eva": "11:11", + "trip_date": "4/11/2022", + "first_address_lat": "50.8996568140536", + "first_address_lng": "5.75238472757395", + "started": "true", + "all_tasks_finished": "false", + "start_km": "24704", + "end_km": null, + "tasks_enriched": "true", + "in_trip_scan_finished": "true", + "eva_added": "true", + "trip_start_request_sent": "true" } ] } @@ -64,14 +88,12 @@ class StoregearApiService extends IStoregearApiService { @override Future<RouteList> getRoutes() async { - return _getMockRouteList(); + //return _getMockRouteList(); - debugPrint('WE GOT HERE!!! ' + apiKey); final response = await http.get( Uri.parse('http://dhlapis.com/delivery/v1/routes'), headers: {'X-API-KEY': apiKey}); - debugPrint(response.body); if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. @@ -80,7 +102,6 @@ class StoregearApiService extends IStoregearApiService { if (content["message"] != null) { return RouteList(routes: []); } - debugPrint('amogus'); return RouteList.fromJson(content); } else { // If the server did not return a 200 OK response, @@ -88,4 +109,28 @@ class StoregearApiService extends IStoregearApiService { throw Exception('Failed to load routes'); } } + + Future<DHLRoute.Route?> getRoute(String tripkey) async { + //return MockRouteProviderService().getRoute(int.parse(tripkey)); + + final response = await http.get( + Uri.parse( + 'http://dhlapis.com/delivery/v1/routes/' + tripkey.toString()), + headers: {'X-API-KEY': apiKey}); + + if (response.statusCode == 200) { + // If the server did return a 200 OK response, + // then parse the JSON. + + var content = jsonDecode(response.body); + if (content["message"] != null) { + return null; + } + return DHLRoute.Route.fromJson(content); + } else { + // If the server did not return a 200 OK response, + // then throw an exception. + throw Exception('Failed to load route'); + } + } } |
