Skip to content

Can't use field variable inside runOnPlatformThread  #1627

Closed
@josxha

Description

@josxha

I have a long living jni object _jniProjection that should get passed to the android UI thread. Before v0.12.0 I was able to pass the JReference in and out of the runOnPlatformThread function.

  @override
  Future<LngLatBounds> getVisibleRegion() async {
    final projectionRef = _jniProjection.reference;
    final boundsRef = await runOnPlatformThread<JReference>(() {
      final projection = jni.Projection.fromReference(projectionRef);
      final region = projection.getVisibleRegion();
      final bounds = region.latLngBounds;
      region.release();
      return bounds.reference;
    });
    final jniBounds = jni.LatLngBounds.fromReference(boundsRef);
    final bounds = LngLatBounds(
      longitudeWest: jniBounds.longitudeWest,
      longitudeEast: jniBounds.longitudeEast,
      latitudeSouth: jniBounds.latitudeSouth,
      latitudeNorth: jniBounds.latitudeNorth,
    );
    jniBounds.release();
    return bounds;
  }
warning: The member 'reference' can only be used within its package. (invalid_use_of_internal_member at [maplibre] lib\src\native\widget_state_jni.dart:427)

Since v0.12.0 .reference and .fromReference() are both marked as @internal. I'm not sure if using JReference was the right approach in the first place. Is there a better way of accieving the behaviour? Should direct usage of the JReference be avoided at all?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions