Skip to content

java.lang.IllegalStateException: Surface was already locked! #31

@Zhorenty

Description

@Zhorenty

🧩 Package

yandex_maps_mapkit_lite: 4.18.0-beta

🧠 Description

When using YandexMap inside a Stack along with other Flutter UI elements (e.g., AnimatedSwitcher, Column, SafeArea), the app crashes on Android at launch with the following error:

java.lang.IllegalStateException: Surface was already locked!
    at android.view.Surface$HwuiContext.lockCanvas(Surface.java:1164)
    at android.view.Surface.lockHardwareCanvas(Surface.java:553)
    at io.flutter.plugin.platform.PlatformViewWrapper.draw(Unknown Source:31)
    ...

This appears to happen during the initial composition and rendering of the map, especially when Flutter attempts to build or animate widgets simultaneously with the native map view being initialized.

✅ Steps to Reproduce

Place YandexMap inside a Stack, e.g.:

Stack(
  children: [
    YandexMap(onMapCreated: ...),
    Positioned(top: 0, child: SomeOverlayWidget()),
  ],
);

Add any widget on top of the map (e.g., AnimatedSwitcher, Column, Opacity, etc.).

Launch the app on Android.

Observe crash during or shortly after map creation.

📱 Platform

Android only (reproducible on multiple Android versions)

Occurs with both real devices and emulators

🛠️ Workarounds

Removing AnimatedSwitcher, Column, or wrapping widgets resolves the crash.

Moving YandexMap to a separate IndexedStack layer also helps avoid the crash.

Avoiding Stack and AnimatedWidgets during initial render helps reduce crash rate.

🔍 Possible Cause

This looks like a conflict between Flutter’s layout/render tree and native Android’s SurfaceView drawing. Flutter likely tries to recompose or animate while the native map surface is still in the process of initializing, leading to a double-lock on the Surface.

🧾 Additional Info

Flutter version: 3.35.5

Devices:

  • Redmi A3x
  • Realme 10
  • POCO X6 5G
  • OPPO A5
  • Redmi 12
  • Realme RMX3871
  • Samsung Galaxy A24

Dart version: 3.9.2

💡 Feature Request / Suggestion

Improve compatibility or document limitations of YandexMap usage within Flutter widgets that perform layout or animation.

Expose a recommended way to safely initialize YandexMap within complex Flutter UIs.

Consider using TextureView instead of SurfaceView (if not already), or support proper HybridComposition strategies explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions