getRoute method

  1. @override
Future<MPRoute> getRoute(
  1. MPPoint origin,
  2. MPPoint destination,
  3. List<MPPoint>? stops,
  4. bool? optimize,
)
override

Implementation

@override
Future<MPRoute> getRoute(MPPoint origin, MPPoint destination,
    List<MPPoint>? stops, bool? optimize) async {
  final result =
      await directionsServiceMethodChannel.invokeMethod('DSE_getRoute', {
    'origin': origin._jsonEncode(),
    'destination': destination._jsonEncode(),
    'stops': stops?.map((e) => e._jsonEncode()).toList(),
    'optimize': optimize
  });

  final route = MPRoute.fromJson(result["route"]);
  final error = MPError.fromJson(result["error"]);

  if (route != null) {
    return Future.value(route);
  } else if (error != null) {
    return Future.error(error);
  } else {
    return Future.error(MPError(
        code: MPError.unknownError,
        message: "Did not receieve route object from Platform"));
  }
}