### Start Navigation via Controller Source: https://pub.dev/packages/mapbox_navigation_flutter Initiates the navigation session using the MapBoxNavigationViewController. This should be called after a route has been built. ```dart _controller.startNavigation(); ``` -------------------------------- ### Import Mapbox Navigation Flutter Package Source: https://pub.dev/packages/mapbox_navigation_flutter/install Import the package into your Dart code to start using its navigation functionalities. This line makes the package's classes and functions available in your project. ```dart import 'package:mapbox_navigation_flutter/mapbox_navigation_flutter.dart'; ``` -------------------------------- ### iOS Info.plist Configuration for Embedded Views Source: https://pub.dev/packages/mapbox_navigation_flutter Adds a necessary key to your application's 'info.plist' file to enable the preview of embedded views on iOS. This is part of the setup for embedding the navigation view. ```xml ... io.flutter.embedded_views_preview ... ``` -------------------------------- ### Configure Mapbox Downloads Token Source: https://pub.dev/packages/mapbox_navigation_flutter Add your Mapbox Downloads token with the `downloads:read` scope to your `gradle.properties` file. This token is used for downloading Mapbox binaries. It's recommended to keep this token secure and out of source control. ```properties MAPBOX_DOWNLOADS_TOKEN=sk.XXXXXXXXXXXXXXX ``` ```properties org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true MAPBOX_DOWNLOADS_TOKEN=sk.epe9nE9peAcmwNzKVNqSbFfp2794YtnNepe9nE9peAcmwNzKVNqSbFfp2794YtnN.-HrbMMQmLdHwYb8r ``` -------------------------------- ### Clean and Rebuild iOS Project Source: https://pub.dev/packages/mapbox_navigation_flutter Commands to clean the project, reinstall pods, and rebuild the iOS application. This is a common troubleshooting step for build issues. ```bash cd ios rm -rf Pods Podfile.lock pod install cd .. flutter clean flutter pub get flutter build ios ``` -------------------------------- ### Begin Navigation with Waypoints Source: https://pub.dev/packages/mapbox_navigation_flutter Initiates navigation between a list of specified waypoints. Ensure WayPoint objects are correctly instantiated with name, latitude, and longitude. ```dart final cityhall = WayPoint(name: "City Hall", latitude: 42.886448, longitude: -78.878372); final downtown = WayPoint(name: "Downtown Buffalo", latitude: 42.8866177, longitude: -78.8814924); var wayPoints = List(); wayPoints.add(cityHall); wayPoints.add(downtown); await MapBoxNavigation.instance.startNavigation(wayPoints: wayPoints); ``` -------------------------------- ### Flutter Application Entry Point Source: https://pub.dev/packages/mapbox_navigation_flutter/example This is the main entry point for a Flutter application using the mapbox_navigation_flutter package. It imports necessary Flutter material design widgets and the application's main app widget. ```dart import 'package:flutter/material.dart'; import 'app.dart'; void main() => runApp(const SampleNavigationApp()); ``` -------------------------------- ### Update MainActivity to Extend FlutterFragmentActivity Source: https://pub.dev/packages/mapbox_navigation_flutter Modify your `MainActivity.kt` to extend `FlutterFragmentActivity` instead of `FlutterActivity`. This is required to avoid a `ViewModelStoreOwner` exception. ```kotlin //import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterFragmentActivity class MainActivity: FlutterFragmentActivity() { } ``` -------------------------------- ### Update iOS Deployment Target Source: https://pub.dev/packages/mapbox_navigation_flutter Sets the minimum iOS deployment target to 12.0 or higher in your 'ios/Podfile'. This is required for compatibility with newer Mapbox SDK versions and Swift features. ```ruby platform :ios, '12.0' ``` -------------------------------- ### Add mapbox_navigation_flutter Dependency Source: https://pub.dev/packages/mapbox_navigation_flutter/install Use this command to add the package as a dependency to your Flutter project. This command automatically updates your pubspec.yaml file. ```bash $ flutter pub add mapbox_navigation_flutter ``` -------------------------------- ### Build Route with Multiple Waypoints Source: https://pub.dev/packages/mapbox_navigation_flutter Constructs a navigation route using a list of WayPoint objects. This method should be called after the MapBoxNavigationViewController has been initialized. ```dart var wayPoints = List(); wayPoints.add(_origin); wayPoints.add(_stop1); wayPoints.add(_stop2); wayPoints.add(_stop3); wayPoints.add(_stop4); wayPoints.add(_origin); _controller.buildRoute(wayPoints: wayPoints); ``` -------------------------------- ### Configure Podfile for Mapbox SDK Version Source: https://pub.dev/packages/mapbox_navigation_flutter Overrides the default Mapbox SDK version in your 'ios/Podfile'. This is useful for compatibility or when using specific SDK features. Ensure the target name matches your project. ```ruby post_install do |installer| installer.pods_project.targets.each do |target| if target.name.include?('MapboxNavigation') || target.name.include?('MapboxMaps') target.build_configurations.each do |config| config.build_settings['SWIFT_TREAT_WARNINGS_AS_ERRORS'] = 'NO' config.build_settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'NO' config.build_settings['SWIFT_SUPPRESS_WARNINGS'] = 'YES' end end end end ``` -------------------------------- ### Set Default Route Options Source: https://pub.dev/packages/mapbox_navigation_flutter Configure default options for the Mapbox Navigation SDK, such as initial location, zoom level, and navigation modes. This is an optional step to customize the navigation experience. ```dart MapBoxNavigation.instance.setDefaultOptions(MapBoxOptions( initialLatitude: 36.1175275, initialLongitude: -115.1839524, zoom: 13.0, tilt: 0.0, bearing: 0.0, enableRefresh: false, alternatives: true, voiceInstructionsEnabled: true, bannerInstructionsEnabled: true, allowsUTurnAtWayPoints: true, mode: MapBoxNavigationMode.drivingWithTraffic, mapStyleUrlDay: "https://url_to_day_style", mapStyleUrlNight: "https://url_to_night_style", units: VoiceUnits.imperial, simulateRoute: true, language: "en")) ``` -------------------------------- ### Add Location and Network Permissions Source: https://pub.dev/packages/mapbox_navigation_flutter Include these permissions in your app-level Android Manifest to enable location services and network access for the navigation SDK. ```xml ... ... ``` -------------------------------- ### Add Mapbox Access Token to iOS Info.plist Source: https://pub.dev/packages/mapbox_navigation_flutter Configure your iOS application to use your Mapbox access token by adding it to the Info.plist file. Ensure the access token has the DOWNLOADS:READ scope and is kept private. ```xml MBXAccessToken sk.eyXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` -------------------------------- ### Listen for Navigation Events Source: https://pub.dev/packages/mapbox_navigation_flutter Register a listener to receive real-time events from the Mapbox Navigation SDK, such as route progress changes, arrival, and navigation status updates. This allows you to update your UI accordingly. ```dart MapBoxNavigation.instance.registerRouteEventListener(_onRouteEvent); Future _onRouteEvent(e) async { _distanceRemaining = await _directions.distanceRemaining; _durationRemaining = await _directions.durationRemaining; switch (e.eventType) { case MapBoxEvent.progress_change: var progressEvent = e.data as RouteProgressEvent; _arrived = progressEvent.arrived; if (progressEvent.currentStepInstruction != null) _instruction = progressEvent.currentStepInstruction; break; case MapBoxEvent.route_building: case MapBoxEvent.route_built: _routeBuilt = true; break; case MapBoxEvent.route_build_failed: _routeBuilt = false; break; case MapBoxEvent.navigation_running: _isNavigating = true; break; case MapBoxEvent.on_arrival: _arrived = true; if (!_isMultipleStop) { await Future.delayed(Duration(seconds: 3)); await _controller.finishNavigation(); } else {} // Handle multiple stops if needed break; case MapBoxEvent.navigation_finished: case MapBoxEvent.navigation_cancelled: _routeBuilt = false; _isNavigating = false; break; default: break; } //refresh UI setState(() {}); } ``` -------------------------------- ### Add Mapbox Access Token XML Source: https://pub.dev/packages/mapbox_navigation_flutter Place your Mapbox API access token in this XML resource file. Ensure the file path is correct within your Android app's structure. ```xml ADD_MAPBOX_ACCESS_TOKEN_HERE ``` -------------------------------- ### Declare mapbox_navigation_flutter Dependency in pubspec.yaml Source: https://pub.dev/packages/mapbox_navigation_flutter/install This is how the mapbox_navigation_flutter dependency will appear in your pubspec.yaml file after running `flutter pub add`. It ensures the package is included in your project. ```yaml dependencies: mapbox_navigation_flutter: ^0.1.4 ``` -------------------------------- ### Declare MapBoxNavigationViewController Source: https://pub.dev/packages/mapbox_navigation_flutter Declare the controller variable used to interact with the embedded Mapbox Navigation View. This is necessary before adding the view to the widget tree. ```dart MapBoxNavigationViewController _controller; ``` -------------------------------- ### Add MapBoxNavigationView to Widget Tree Source: https://pub.dev/packages/mapbox_navigation_flutter Embeds the Mapbox Navigation View within your Flutter widget tree. The 'onCreated' callback is crucial for initializing the controller. ```dart Container( color: Colors.grey, child: MapBoxNavigationView( options: _options, onRouteEvent: _onRouteEvent, onCreated: (MapBoxNavigationViewController controller) async { _controller = controller; }), ), ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.