Reputation: 53
I am trying to call a method from a kotlin class on a android module from a dart class, however, I keep receiving the
MissingPluginException(No implementation found for method on channel)
couldnt find anything wrong with it
dart code:
class ****{
MethodChannel _methodChannel = MethodChannel('android3ds/channel');
customizar() async {
try {
await _methodChannel.invokeMethod('customizar');
} on PlatformException catch (e) {
print(e);
}
}
kotlin code
class *****(var activity: Activity, val environment: Environment) {
lateinit var flutterEngine : FlutterEngine
val CHANNEL = "android3ds/channel"
val methodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).
setMethodCallHandler { call, result ->
if (call.equals("customizar")) {
customizar()
}
}
fun customizar() {
}
Upvotes: 1
Views: 2082
Reputation: 53
Called the kotlin class from the MainActivity.kt and it worked:
internal class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
var kotlin_class: **** = ****(this, Environment.SANDBOX)
provideFlutterEngine(this)?.let { GeneratedPluginRegistrant.registerWith(it) }
val CHANNEL = "android3ds/name"
val methodChannel = MethodChannel(flutterEngine?.dartExecutor?.binaryMessenger, CHANNEL).
setMethodCallHandler{ call, result ->
if (call.method.equals("customizar")){
kotlin_class.customizar()
}
}
}
}
Upvotes: 3