Merge pull request #1 from Iconica-Development/bugfix/move-away-from-then

Move away from .then and use await instead
This commit is contained in:
Bart Ribbers 2023-01-25 10:10:16 +01:00 committed by GitHub
commit 960d5fb597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 52 deletions

View file

@ -130,32 +130,30 @@ class _TrackTraceDemoState extends State<TrackTraceDemo> {
); );
} }
void loadBitmapImages() { Future<void> loadBitmapImages() async {
rootBundle.load('assets/profile_picture.png').then((value) { var loadedPicture = await rootBundle.load('assets/profile_picture.png');
convertBytesToCustomBitmapDescriptor( var bitmap = await convertBytesToCustomBitmapDescriptor(
value.buffer.asUint8List(), loadedPicture.buffer.asUint8List(),
size: 80, size: 80,
addBorder: true, addBorder: true,
borderColor: Colors.grey, borderColor: Colors.grey,
title: 'Alex', title: 'Alex',
titleBackgroundColor: Color(0xffff7884), titleBackgroundColor: Color(0xffff7884),
).then((bitmap) { );
startMarkerIcon = bitmap;
BitmapDescriptor.fromAssetImage( startMarkerIcon = bitmap;
ImageConfiguration(size: Size(100, 100)), var bitmapDescriptor = await BitmapDescriptor.fromAssetImage(
'assets/ic_location_on.png', ImageConfiguration(size: Size(100, 100)),
).then((value) { 'assets/ic_location_on.png',
setState(() { );
destinationMarkerIcon = value; setState(() {
controller?.end = Marker( destinationMarkerIcon = bitmapDescriptor;
anchor: Offset(0.5, 0.5), controller?.end = Marker(
markerId: MarkerId('Bestemming Locatie'), anchor: Offset(0.5, 0.5),
position: LatLng(52.364709, 4.877157), markerId: MarkerId('Bestemming Locatie'),
icon: value, position: LatLng(52.364709, 4.877157),
); icon: bitmapDescriptor,
}); );
});
});
}); });
} }

View file

@ -227,32 +227,28 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
} }
} }
void calculateRoute() { Future<void> calculateRoute() async {
if (controller.route == null || checkTargetMoved()) { if (controller.route == null || checkTargetMoved()) {
DirectionsRepository() // TODO(freek): refactor this away var directions =
.getDirections( await DirectionsRepository() // TODO(freek): refactor this away
origin: controller.start.position, .getDirections(
destination: controller.end.position, origin: controller.start.position,
mode: widget.travelMode, destination: controller.end.position,
key: widget.googleAPIKey, mode: widget.travelMode,
) key: widget.googleAPIKey,
.then( );
(Directions? directions) => { if (directions != null) {
if (directions != null) controller.route = TrackTraceRoute(
{ directions.totalDuration,
controller.route = TrackTraceRoute( directions.totalDistance,
directions.totalDuration, directions.polylinePoints,
directions.totalDistance, );
directions.polylinePoints, checkDestinationCloseBy();
), controller.recenterCamera();
checkDestinationCloseBy(), setState(() {
controller.recenterCamera(), lastRouteUpdate = DateTime.now();
setState(() { });
lastRouteUpdate = DateTime.now(); }
}),
}
},
);
} }
} }

View file

@ -1,6 +1,6 @@
name: google_track_trace name: google_track_trace
description: An Iconica Flutter pluginin for Track & Trace Package description: An Iconica Flutter pluginin for Track & Trace Package
version: 1.0.1 version: 1.0.2
environment: environment:
sdk: ">=2.14.0 <3.0.0" sdk: ">=2.14.0 <3.0.0"