Skip to content

onStyleLoaded never fires on Android #478

@sirawatGG

Description

@sirawatGG

Platforms

Android

Version of flutter-maplibre

0.3.3+2

Bug Description

onStyleLoaded (and MapEventStyleLoaded) never fires on Android. The map loads visually but the callback is never invoked.

Ai was able to resolve this issue by this code change

Image
  1. Missing onStyleLoaded$async = true
    The JNI bridge defaults to onStyleLoaded$async = false, which attempts to call Dart synchronously from the Android main thread. Since Dart runs on a separate isolate, this is undefined behavior and silently fails.

Compare: _CameraMovementCallback correctly sets onCancel$async = true and onFinish$async = true, but _StyleLoadedCallback was missing the equivalent.

  1. WeakReference wrapping a method tearoff
    // Before (broken)
_StyleLoadedCallback(WeakReference(onStyleLoaded))
onStyleLoaded written this way creates a temporary tearoff object with no strong holder. Dart's GC collects it almost immediately. By the time MapLibre fires the callback asynchronously (after downloading/parsing the style), weakCallback.target is null and the callback does nothing.

Steps to Reproduce

  1. Run on an Android device or emulator
  2. Wait for the map to fully render
  3. Observe that onStyleLoaded is never called — no print, no state update, nothing

Expected Results

It should call onStyleLoaded

Actual Results

It never call onStyleLoaded

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidAndroid specific issuebugSomething isn't workingquestionFurther information is requested

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions