Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

null check added to avoid NPE while calling FlutterView.detachFromFlutterEngine() #41082

Merged
merged 9 commits into from
Apr 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,13 @@ void onDestroyView() {
flutterView.getViewTreeObserver().removeOnPreDrawListener(activePreDrawListener);
activePreDrawListener = null;
}
flutterView.detachFromFlutterEngine();
flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener);

// flutterView can be null in instances where a delegate.onDestroyView is called without
// onCreateView being called. See https://github.com/flutter/engine/pull/41082 for more detail.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in general the code should stand in isolation; there's no guarantee that the issue database will last as long as the code comments. so if there is more useful data to include it would be good to just describe it all here rather than linking to the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree which is why there is a description before the link. That said this link has way more information than I think could (should?) fit in a comment include screenshots and statements about androids observed behavior. All in if someone wanted to understand why how onDestroyView can be called without onCreateView then the link is the best place to learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general if we think more documentation is needed, then I would recommend putting it in a README.md, or, at the extreme, in a wiki page. We shouldn't consider PR descriptions to be canonical documentation sources.

if (flutterView != null) {
flutterView.detachFromFlutterEngine();
flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener);
}
}

void onSaveInstanceState(@Nullable Bundle bundle) {
Expand Down