im tryeing to add yandex map to flutter app using yandex_mapkit 4.0.2 plugin i followed all the steps in the docs but i get this error in the run time
E/flutter ( 5705): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: yandex_mapkit/yandex_map
i think the error because of this step of the setup for android because i cant use this code in my MainActivity.js
Specify your API key and locale in your custom application class. If you don't have one the you can create it like so android/app/src/main/.../MainApplication.java
import android.app.Application;
import com.yandex.mapkit.MapKitFactory;
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
MapKitFactory.setLocale("YOUR_LOCALE"); // Your preferred language. Not required, defaults to system language
MapKitFactory.setApiKey("YOUR_API_KEY"); // Your generated API key
}
}
when i add the same code it give me this errors
error: method does not override or implement a method from a supertype @Override
error: no suitable method found for onCreate(no arguments) super.onCreate();
so instead im using this code in my MainActivity.js file and i have that run time error Trying to create a platform view of unregistered type
package com.example.mapkit;
import com.yandex.mapkit.MapKitFactory;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
public void onCreate() {
MapKitFactory.setLocale("en_US"); // Your preferred language. Not required, defaults to system language
MapKitFactory.setApiKey("APIKEY...."); // Your generated API key
}
}
i tryed flutter clean and i rebuild the project even tried to start again with a new project for only trying to integrate the map but still same errors
2
Answers
it seems that the problem is from the plugin itself i had to use the official flutter plugin from yandex yandex_maps_mapkit https://pub.dev/packages/yandex_maps_mapkit its easier to configure and work fine with android and ios with 2 lines of code i got everything working i dont know why the other unofficial plugin is more popular
Use a special plugin. Instructions for use are in the documentation in the Flutter section. Please pay attention to the versions of MapKit and the Flutter plugin before using.