diff --git a/packages/flutter/lib/src/services/message_codec.dart b/packages/flutter/lib/src/services/message_codec.dart index ba99134778..32fc4773cb 100644 --- a/packages/flutter/lib/src/services/message_codec.dart +++ b/packages/flutter/lib/src/services/message_codec.dart @@ -145,6 +145,51 @@ class PlatformException implements Exception { /// print(stacktrace); /// } /// ``` + /// + /// On Android this field is populated when a `RuntimeException` or a subclass of it is thrown in the method call handler, + /// as shown in the following example: + /// + /// ```kotlin + /// import androidx.annotation.NonNull + /// import io.flutter.embedding.android.FlutterActivity + /// import io.flutter.embedding.engine.FlutterEngine + /// import io.flutter.plugin.common.MethodChannel + /// + /// class MainActivity: FlutterActivity() { + /// private val CHANNEL = "channel_name" + /// + /// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + /// super.configureFlutterEngine(flutterEngine) + /// MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + /// call, result -> throw RuntimeException("Oh no") + /// } + /// } + /// } + /// ``` + /// + /// It is also populated on Android if the method channel result is not serializable. + /// If the result is not serializable, an exception gets thrown during the serialization process. + /// This can be seen in the following example: + /// + /// ```kotlin + /// import androidx.annotation.NonNull + /// import io.flutter.embedding.android.FlutterActivity + /// import io.flutter.embedding.engine.FlutterEngine + /// import io.flutter.plugin.common.MethodChannel + /// + /// class MainActivity: FlutterActivity() { + /// private val CHANNEL = "channel_name" + /// + /// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + /// super.configureFlutterEngine(flutterEngine) + /// MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + /// call, result -> result.success(Object()) + /// } + /// } + /// } + /// ``` + /// + /// In the cases described above, the content of [stacktrace] will be the unprocessed output of calling `toString()` on the exception. final String? stacktrace; @override