Move away from .then and use await instead

This commit is contained in:
Bart Ribbers 2023-01-25 09:57:28 +01:00
parent 9ed9a2f295
commit 8c987dfa7d
3 changed files with 46 additions and 52 deletions

View file

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

View file

@ -227,32 +227,28 @@ class _GoogleTrackTraceMapState extends State<GoogleTrackTraceMap> {
}
}
void calculateRoute() {
Future<void> calculateRoute() async {
if (controller.route == null || checkTargetMoved()) {
DirectionsRepository() // TODO(freek): refactor this away
var directions =
await 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)
{
);
if (directions != null) {
controller.route = TrackTraceRoute(
directions.totalDuration,
directions.totalDistance,
directions.polylinePoints,
),
checkDestinationCloseBy(),
controller.recenterCamera(),
);
checkDestinationCloseBy();
controller.recenterCamera();
setState(() {
lastRouteUpdate = DateTime.now();
}),
});
}
},
);
}
}

View file

@ -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"