diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 72b1f56167d95a969c837998d271546c9fa4a4f3..9a72419016bfd7fa43d5869a36aa33f730665c04 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -237,6 +237,21 @@ public class TextInputPlugin { return lastInputConnection; } + /** + * Clears a platform view text input client if it is the current input target. + * + * This is called when a platform view is disposed to make sure we're not hanging to a stale input + * connection. + */ + public void clearPlatformViewClient(int platformViewId) { + if (inputTarget.type == InputTarget.Type.PLATFORM_VIEW && inputTarget.id == platformViewId) { + inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, 0); + hideTextInput(mView); + mImm.restartInput(mView); + mRestartInputPending = false; + } + } + private void showTextInput(View view) { view.requestFocus(); mImm.showSoftInput(view, 0); diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 334d2d18dcfd940943c87d0f5e228ce6a76b8cb6..8ea704b39c733deb0a8c2e8c719713536568832e 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -135,8 +135,11 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega + viewId); } - contextToPlatformView.remove(vdController.getView().getContext()); + if (textInputPlugin != null) { + textInputPlugin.clearPlatformViewClient(viewId); + } + contextToPlatformView.remove(vdController.getView().getContext()); vdController.dispose(); vdControllers.remove(viewId); }