-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Steps to reproduce
I'd like to file an issue for Flutter. Similar to #149792, but that issue was closed without being resolved, and this problem occurs in the latest version. I’ll add some additional details.
In https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java, the following code block:
if (host.attachToEngineAutomatically()) {
Log.v(TAG, "Attaching FlutterEngine to FlutterView.");
flutterView.attachToFlutterEngine(flutterEngine);
}allows FlutterView to be configured to not attach to the engine automatically, which is a useful feature that enables users to attach it later when needed. However, this leads to an issue: when the FlutterFragment lifecycle reaches onCreateView, and host.attachToEngineAutomatically() returns false, flutterView.attachToFlutterEngine(flutterEngine) is not executed. Meanwhile, the textInputPlugin in FlutterView is initialized in attachToFlutterEngine. If attachToFlutterEngine is not executed, but the method
@Override
public void onProvideAutofillVirtualStructure(@NonNull ViewStructure structure, int flags) {
super.onProvideAutofillVirtualStructure(structure, flags);
textInputPlugin.onProvideAutofillVirtualStructure(structure, flags);
}is invoked, it will eventually cause a null pointer exception due to textInputPlugin being uninitialized.
My suggestion is to add a null check for textInputPlugin to prevent this issue.
Expected results
App crashed.
Actual results
App crashed.
Code sample
no
Screenshots or Video
No response
Logs
Flutter Doctor output
no