FULL AI ANALYSIS

Flutter app renders black screen on foldable Android phones after fold/unfold events — display density and PlatformView mismatch

Generated Oct 3, 2026, 12:35:03 AM

Analysis summary

Foldable transitions change physical display metrics and can trigger the Android window to recreate surfaces. PlatformViews create a separate native surface layer which the Flutter compositor must embed; when display metrics change or surfaces are destroyed and recreated rapidly, the engine may fail to rebind the PlatformView to the new compositor surface, leaving a black region. Release builds' performance optimizations and differences in timing can expose race conditions. The presence of SurfaceControl errors in logs and successful debug-mode runs indicate a potential race or missing lifecycle handling in the Flutter embedding or the platform view implementation.

Possible causes

Race between Android window surface recreation on configuration change and Flutter engine attempting to reattach PlatformView, leaving an uninitialized compositor surface.

90%

Incorrect handling of display density/size changes in the embedding that does not recreate or resize the FlutterSurfaceView properly after fold transitions.

85%

PlatformView implementation (native video player) not handling on surfaceDestroyed/on surfaceCreated lifecycle during configuration changes.

70%

GPU/driver bug on specific OEM foldable devices where surface destruction callbacks are not propagated reliably to app surfaces.

50%

Suggested fixes

1

Diagnostic step 1

Capture detailed logcat including Flutter engine logs and SurfaceControl messages during a reproduce; include timestamps and stack traces for surface creation/destruction events and redact sensitive tokens.

2

Diagnostic step 2

Implement a robust WidgetsBindingObserver.didChangeMetrics handler that forces a safe reinitialize of the PlatformView: stop the native view, call setState to remove it from the widget tree, schedule a delayed re-add after 100–250 ms to allow the system to recreate surfaces (test varying delays).

3

Diagnostic step 3

In the embedding (MainActivity), listen for onConfigurationChanged and forward events to the Flutter engine; ensure FlutterActivity is using the v2 embedding and PlatformView lifecycle helpers.

4

Diagnostic step 4

Experiment in a staging build with additional sanity checks: onActivityPaused/onActivityResumed explicitly recreating the PlatformView and preserving user state externally (e.g., player position) to avoid data loss.

5

Diagnostic step 5

If reproducible after these app-level mitigations, gather minimized repro and Flutter engine version and file an issue against the Flutter engine and/or the OEM vendor if SurfaceControl/driver errors persist; escalate with device logs and exact reproduction steps.