Note: This question is specifically for `flutter.android.dart`.
How does the MethodChannel of Flutter works internally, like:
I know that MethodChannel first serializes the messages, before passing, but how, and what?
Is the kotlin/java side, always listening for a connection from dart side, like a web server does?, or
Is it android which calls the kotlin-side code, upon request from dart-side?, or
something else
Also, how is a MethodChannel different, from the Kotlin/Java interop with dart (which is an incoming feature, coming with dart 3, next year), like:
Is one efficient, than the other, or are they almost similar, in performance, and at other parameters, and
For example, to use
PDFRenderer
on a document(Uint8List
), of size 4 MiB, needs to be processed, which one method (among MethodChannel and interop)would be a better choice,
How is the following code expected to be changed to, to use kotlin interop, both at dart, and kotlin side:
package com.exa.mple
import android.net.Uri
import android.os.Build
import android.os.ParcelFileDescriptor
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import java.io.File
class MainActivity : FlutterActivity() {
private val METHOD_CHANNEL: String = "com.example/method-channel";
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, METHOD_CHANNEL).setMethodCallHandler { request: MethodCall, response: MethodChannel.Result ->
if (request.method == "getPlatformSDKVersion") {
response.success(Build.VERSION.SDK_INT.toString());
} else if (request.method == "getPrivateFilesDirPath") {
response.success(context.filesDir.absolutePath);
} else {
response.notImplemented();
}
}
}
}
I searched google, reddit, stack-overflow, even quora, thoroughly, tought found some info, but nothing satisfactory
Thanking you...