flutter_mapbox_navigation: The startNavigation method dont work

When using this plugin and following all the installation steps, it is impossible to register it correctly. It seems a compatibility issue. my pubspect.ymal and my implementation

`name: apppalermodev description: A new Flutter project. environment: sdk: “>=2.2.2 ❤️.0.0”

dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter flutter_cupertino_localizations: ^1.0.1 expandable: ^4.0.1 fluttertoast: ^3.1.3 english_words: ^3.1.3 cupertino_icons: ^0.1.2 flutter_socket_io: ^0.6.0 rxdart: ^0.22.2 device_info: ^0.4.0+3 shared_preferences: ^0.5.2 http: ^0.12.0+2 sqflite: ^1.1.5 path_provider: ^1.3.0 connectivity: ^0.4.2 encrypt: ^3.3.1 blue_thermal_printer: ^1.0.9 pull_to_refresh: ^1.4.5 image_picker: ^0.6.2+3 badges: ^1.1.0 progress_hud: ^1.1.0 carousel_slider: ^1.3.0 rflutter_alert: ^1.0.3 crypto: ^2.1.3 location: ^2.3.5 flutter_bcrypt: ^1.0.5 dbcrypt: ^1.0.0 flutter_speed_dial: ^1.2.5 flutter_map: ^0.8.2 latlong: ^0.6.1 bitmap: ^0.0.6 flutter_mapbox_navigation: ^0.0.8

dev_dependencies: flutter_test: sdk: flutter mapbox_gl: path: ./dependencies/flutter-mapbox-gl

module: androidX: true

flutter:

uses-material-design: true assets:

  • media/
  • assets/
  • assets/symbols/
  • assets/img/
  • assets/img/modulos/
  • lib/src/utils/languages/ fonts: - family: CenturyGothic fonts:
    • asset: assets/fonts/CenturyGothicRegular.ttf `

` class MapReconexionState extends State<MapReconexion> { bool _arrived = false; double _distanceRemaining, _durationRemaining; bool _tilesLoaded = false; … @override void initState() { super.initState(); _copyTilesIntoPlace(); initPlatformState(); }

Future<void> initPlatformState() async { // If the widget was removed from the tree while the asynchronous platform // message was in flight, we want to discard the reply rather than calling // setState to update our non-existent appearance. if (!mounted) return;

_directions = mapbox.MapboxNavigation(onRouteProgress: (arrived) async {
  _distanceRemaining = await _directions.distanceRemaining;
  _durationRemaining = await _directions.durationRemaining;

  setState(() {
    _arrived = arrived;
  });
  if (arrived) await _directions.finishNavigation();
});

} … Future<void> turnOnNavigation ({String origenName, String targetName, LatLng origin, LatLng target}) async {

if (origin == null) {
  await getLoaction();
}

final _origin = mapbox.Location(name: "City Hall", latitude: 42.886448, longitude: -78.878372);
final _destination = mapbox.Location(name: "Downtown Buffalo", latitude: 42.8866177, longitude: -78.8814924);

await _directions.startNavigation(
  origin: _origin,
  destination: _destination,
  mode: mapbox.NavigationMode.drivingWithTraffic,
  simulateRoute: true);

} … PopupMenu( title: “Empezar viaje”, onTap: () { turnOnNavigation(); }, icon: Icons.directions_car) … } ` My error

Exception has occurred. MissingPluginException (MissingPluginException(No implementation found for method startNavigation on channel flutter_mapbox_navigation))

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 22 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I have found a workaround for this

Navigate to com.dormmom.flutter_mapbox_navigation.FlutterMapboxNavigationPlugin file as shown below Screenshot 2020-02-20 at 4 03 29 PM

add (act:Activity) as a initializer to the FlutterMapboxNavigationPlugin class

like this

class FlutterMapboxNavigationPlugin(act: Activity): FlutterPlugin, ActivityAware

add initializer in the class

init {
        _activity = act;
    }

pass registrar.activity() as argument to the FlutterMapboxNavigationPlugin Object

val instance = FlutterMapboxNavigationPlugin(registrar.activity())

add following line in private onAttachedToEngine function

val handler = FlutterMapboxNavigation(_context, _activity)
        _eventChannel!!.setStreamHandler(handler)
        _methodChannel!!.setMethodCallHandler(handler)

And you are done

full code for FlutterMapboxNavigationPlugin file below

import android.app.Activity
import android.content.Context

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding

import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry.Registrar

class FlutterMapboxNavigationPlugin(act: Activity): FlutterPlugin, ActivityAware
{
    
    private var _methodChannel: MethodChannel? = null
    private var _eventChannel: EventChannel? = null
    private lateinit var _activity: Activity
    private lateinit var _context: Context

    companion object {
        @Suppress("unused")
        @JvmStatic
        fun registerWith(registrar: Registrar) {

            val instance = FlutterMapboxNavigationPlugin(registrar.activity())
            instance.onAttachedToEngine(registrar.activeContext(), registrar.messenger())

        }
    }

    init {
        _activity = act;
    }

    override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {

        onAttachedToEngine(binding.applicationContext, binding.binaryMessenger)

    }

    override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {

        _methodChannel!!.setMethodCallHandler(null)
        _methodChannel = null
        _eventChannel!!.setStreamHandler(null)
        _eventChannel = null

    }


    private fun onAttachedToEngine(binding: Context, messenger: BinaryMessenger) {

        _context = binding
        _methodChannel = MethodChannel(messenger, "flutter_mapbox_navigation")
        _eventChannel = EventChannel(messenger, "flutter_mapbox_navigation/arrival")
        val handler = FlutterMapboxNavigation(_context, _activity)
        _eventChannel!!.setStreamHandler(handler)
        _methodChannel!!.setMethodCallHandler(handler)

    }

    override fun onDetachedFromActivity() {
        _activity.finish()
    }

    override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
        
    }

    override fun onAttachedToActivity(binding: ActivityPluginBinding) {
        _activity = binding.activity
        val handler = FlutterMapboxNavigation(_context, _activity)
        _eventChannel!!.setStreamHandler(handler)
        _methodChannel!!.setMethodCallHandler(handler)
    }

    override fun onDetachedFromActivityForConfigChanges() {
        //To change body of created functions use File | Settings | File Templates.
    }


}


What is your exact flutter version. Please provide flutter doctor -v output