From aaee816c89f76c3d58513878102717583c4a07e6 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Tue, 11 Jun 2019 15:21:55 -0700 Subject: [PATCH] Fix TextInputPlugin NPE caused by PlatformViewsController ref in new embedding (#34283). (flutter/engine#9283) --- .../io/flutter/plugin/editing/TextInputPlugin.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 0e654277f3..42fdd581ab 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -46,7 +46,8 @@ public class TextInputPlugin { // target is a platform view. See the comments on lockPlatformViewInputConnection for more details. private boolean isInputConnectionLocked; - public TextInputPlugin(View view, @NonNull DartExecutor dartExecutor, PlatformViewsController platformViewsController) { + // TODO(mattcarroll): change @Nullable to @NonNull once new embedding integrates PlatformViewsController. + public TextInputPlugin(View view, @NonNull DartExecutor dartExecutor, @Nullable PlatformViewsController platformViewsController) { mView = view; mImm = (InputMethodManager) view.getContext().getSystemService( Context.INPUT_METHOD_SERVICE); @@ -84,7 +85,10 @@ public class TextInputPlugin { } }); this.platformViewsController = platformViewsController; - platformViewsController.attachTextInputPlugin(this); + // TODO(mattcarroll): remove if-statement once new embedding integrates PlatformViewsController. + if (platformViewsController != null) { + platformViewsController.attachTextInputPlugin(this); + } } @NonNull @@ -123,7 +127,10 @@ public class TextInputPlugin { * The TextInputPlugin instance should not be used after calling this. */ public void destroy() { - platformViewsController.detachTextInputPlugin(); + // TODO(mattcarroll): Remove if-statement once new embedding integrates PlatformViewsController. + if (platformViewsController != null) { + platformViewsController.detachTextInputPlugin(); + } } private static int inputTypeFromTextInputType(