Skip to content

customData updates lost on Android when calling PointAnnotationManager.update #1107

@cohenadair

Description

@cohenadair

Note that this was tested with 2.18. I'm unable to test with 2.19 due to #1106.

This is only an issue on Android, iOS works as expected. Essentially, when a point annotation has its customData field set, and it is updated with PointAnnotationManager.update, the updated customData is lost. Run the example app below, click the "Update" button, and view the results in the console:

Result on Android:

I/flutter ( 8421): Current custom data: {test_key: test_value}
I/flutter ( 8421): New custom data: {test_key_updated: test_value_updated}
I/flutter ( 8421): Post updated custom data: {test_key: test_value}

Result on iOS:

flutter: Current custom data: {test_key: test_value}
flutter: New custom data: {test_key_updated: test_value_updated}
flutter: Post updated custom data: {test_key_updated: test_value_updated}

import 'package:flutter/material.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  MapboxOptions.setAccessToken(
    "",
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: "Mapbox", home: const MyHomePage());
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late PointAnnotationManager _pointManager;
  late PointAnnotation _annotation;

  @override
  Widget build(BuildContext context) {
    final start = Point(coordinates: Position(-74.00913, 40.75183));
    return Scaffold(
      body: MapWidget(
        cameraOptions: CameraOptions(center: start, zoom: 15),
        onMapCreated: (map) async {
          _pointManager = await map.annotations.createPointAnnotationManager();
          _annotation = await _pointManager.create(
            PointAnnotationOptions(
              geometry: start,
              customData: {"test_key": "test_value"},
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          print("Current custom data: ${_annotation.customData}");

          final customData = {"test_key_updated": "test_value_updated"};
          print("New custom data: $customData");

          await _pointManager.update(_annotation..customData = customData);

          print(
            "Post updated custom data: ${(await _pointManager.getAnnotations()).first.customData}",
          );
        },
        child: Text("Update"),
      ),
    );
  }
}

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