diff --git a/example/lib/main.dart b/example/lib/main.dart index 9e66bd5..12e59f9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -130,32 +130,30 @@ class _TrackTraceDemoState extends State { ); } - void loadBitmapImages() { - rootBundle.load('assets/profile_picture.png').then((value) { - convertBytesToCustomBitmapDescriptor( - value.buffer.asUint8List(), - size: 80, - addBorder: true, - borderColor: Colors.grey, - title: 'Alex', - titleBackgroundColor: Color(0xffff7884), - ).then((bitmap) { - startMarkerIcon = bitmap; - BitmapDescriptor.fromAssetImage( - ImageConfiguration(size: Size(100, 100)), - 'assets/ic_location_on.png', - ).then((value) { - setState(() { - destinationMarkerIcon = value; - controller?.end = Marker( - anchor: Offset(0.5, 0.5), - markerId: MarkerId('Bestemming Locatie'), - position: LatLng(52.364709, 4.877157), - icon: value, - ); - }); - }); - }); + Future loadBitmapImages() async { + var loadedPicture = await rootBundle.load('assets/profile_picture.png'); + var bitmap = await convertBytesToCustomBitmapDescriptor( + loadedPicture.buffer.asUint8List(), + size: 80, + addBorder: true, + borderColor: Colors.grey, + title: 'Alex', + titleBackgroundColor: Color(0xffff7884), + ); + + startMarkerIcon = bitmap; + var bitmapDescriptor = await BitmapDescriptor.fromAssetImage( + ImageConfiguration(size: Size(100, 100)), + 'assets/ic_location_on.png', + ); + setState(() { + destinationMarkerIcon = bitmapDescriptor; + controller?.end = Marker( + anchor: Offset(0.5, 0.5), + markerId: MarkerId('Bestemming Locatie'), + position: LatLng(52.364709, 4.877157), + icon: bitmapDescriptor, + ); }); } diff --git a/lib/src/google_map.dart b/lib/src/google_map.dart index da098b3..76c9bd2 100644 --- a/lib/src/google_map.dart +++ b/lib/src/google_map.dart @@ -227,32 +227,28 @@ class _GoogleTrackTraceMapState extends State { } } - void calculateRoute() { + Future calculateRoute() async { if (controller.route == null || checkTargetMoved()) { - DirectionsRepository() // TODO(freek): refactor this away - .getDirections( - origin: controller.start.position, - destination: controller.end.position, - mode: widget.travelMode, - key: widget.googleAPIKey, - ) - .then( - (Directions? directions) => { - if (directions != null) - { - controller.route = TrackTraceRoute( - directions.totalDuration, - directions.totalDistance, - directions.polylinePoints, - ), - checkDestinationCloseBy(), - controller.recenterCamera(), - setState(() { - lastRouteUpdate = DateTime.now(); - }), - } - }, - ); + var directions = + await DirectionsRepository() // TODO(freek): refactor this away + .getDirections( + origin: controller.start.position, + destination: controller.end.position, + mode: widget.travelMode, + key: widget.googleAPIKey, + ); + if (directions != null) { + controller.route = TrackTraceRoute( + directions.totalDuration, + directions.totalDistance, + directions.polylinePoints, + ); + checkDestinationCloseBy(); + controller.recenterCamera(); + setState(() { + lastRouteUpdate = DateTime.now(); + }); + } } } diff --git a/pubspec.yaml b/pubspec.yaml index 4564d5d..6a79fae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: google_track_trace description: An Iconica Flutter pluginin for Track & Trace Package -version: 1.0.1 +version: 1.0.2 environment: sdk: ">=2.14.0 <3.0.0"