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,33 +130,31 @@ 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; startMarkerIcon = bitmap;
BitmapDescriptor.fromAssetImage( var bitmapDescriptor = await BitmapDescriptor.fromAssetImage(
ImageConfiguration(size: Size(100, 100)), ImageConfiguration(size: Size(100, 100)),
'assets/ic_location_on.png', 'assets/ic_location_on.png',
).then((value) { );
setState(() { setState(() {
destinationMarkerIcon = value; destinationMarkerIcon = bitmapDescriptor;
controller?.end = Marker( controller?.end = Marker(
anchor: Offset(0.5, 0.5), anchor: Offset(0.5, 0.5),
markerId: MarkerId('Bestemming Locatie'), markerId: MarkerId('Bestemming Locatie'),
position: LatLng(52.364709, 4.877157), position: LatLng(52.364709, 4.877157),
icon: value, icon: bitmapDescriptor,
); );
}); });
});
});
});
} }
void getRandomPointOnMap() { void getRandomPointOnMap() {

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 =
await DirectionsRepository() // TODO(freek): refactor this away
.getDirections( .getDirections(
origin: controller.start.position, origin: controller.start.position,
destination: controller.end.position, destination: controller.end.position,
mode: widget.travelMode, mode: widget.travelMode,
key: widget.googleAPIKey, key: widget.googleAPIKey,
) );
.then( if (directions != null) {
(Directions? directions) => {
if (directions != null)
{
controller.route = TrackTraceRoute( controller.route = TrackTraceRoute(
directions.totalDuration, directions.totalDuration,
directions.totalDistance, directions.totalDistance,
directions.polylinePoints, directions.polylinePoints,
), );
checkDestinationCloseBy(), checkDestinationCloseBy();
controller.recenterCamera(), controller.recenterCamera();
setState(() { setState(() {
lastRouteUpdate = DateTime.now(); 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"