mirror of
https://github.com/Iconica-Development/flutter_google_track_and_trace.git
synced 2025-05-19 13:13:44 +02:00
Move away from .then and use await instead
This commit is contained in:
parent
9ed9a2f295
commit
8c987dfa7d
3 changed files with 46 additions and 52 deletions
|
@ -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() {
|
||||||
|
|
|
@ -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();
|
||||||
}),
|
});
|
||||||
}
|
}
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue