Skip to content

Flutter Mapbox navigation auto exit after navigation done #389

Open

Description

@Byte-Builders24

Is there is a way to automatically navigate another screen when user reached to the location without showing this end navigation screen. Its only goto next screen after clicked end navigation. I want to do this automatically

Simulator Screenshot - iPhone 15 Pro - 2025-01-08 at 11 08 03

Future _onEmbeddedRouteEvent(e) async {
_distanceRemaining = await MapBoxNavigation.instance.getDistanceRemaining();
_durationRemaining = await MapBoxNavigation.instance.getDurationRemaining();

switch (e.eventType) {
  case MapBoxEvent.progress_change:
    var progressEvent = e.data as RouteProgressEvent;
    if (progressEvent.currentStepInstruction != null) {
      _instruction = progressEvent.currentStepInstruction;
    }
    break;
  case MapBoxEvent.route_building:
  case MapBoxEvent.route_built:
    setState(() {
      _routeBuilt = true;
    });
    break;
  case MapBoxEvent.route_build_failed:
    setState(() {
      _routeBuilt = false;
    });
    break;
  case MapBoxEvent.navigation_running:
    setState(() {
      _isNavigating = true;
    });
    break;
  case MapBoxEvent.on_arrival:
    if (!_isMultipleStop) {
      await Future.delayed(const Duration(seconds: 3));
      await _controller?.finishNavigation();

     
    } else {}
    break;
  case MapBoxEvent.navigation_finished:
    await _controller?.finishNavigation();

    Map<String, dynamic> nearestGateData = await findNearestGate();
    Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => NavigationScreen(


                )));

    break;
  case MapBoxEvent.navigation_cancelled:
    setState(() {
      _routeBuilt = false;
      _isNavigating = false;
    });
    break;
  default:
    break;
}
setState(() {});

}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions