Skip to content

[google_maps_flutter] Null safety broken for method isMarkerInfoWindowShown #78426

@stefalda

Description

@stefalda

The method isMarkerInfoWindowShown in file method_channel_google_maps_flutter.dart isn't working with null safety because the channel(mapId).invokeMethod has an optional return type, so forcing it to bool doesn't work.

In the original code a cast has been added to silence the compiler warnings but there is a runtime error when the method is invoked because the signature invokeMethod should be invokeMethod<bool?>:

This is the original implementation

  @override
  Future<bool> isMarkerInfoWindowShown(
    MarkerId markerId, {
    required int mapId,
  }) {
   assert(markerId != null);
   return channel(mapId).invokeMethod<bool>('markers#isInfoWindowShown',
        <String, String>{'markerId': markerId.value}) as Future<bool>;
}

This is a proposed fix for the implementation:

  @override
  Future<bool> isMarkerInfoWindowShown(
    MarkerId markerId, {
    required int mapId,
  }) async {
    assert(markerId != null);
    bool? res  = await channel(mapId).invokeMethod<bool?>('markers#isInfoWindowShown',
        <String, String>{'markerId': markerId.value}) ;
    return res!;
  }

After some comments the new fix implementation schould be

  @override
  Future<bool> isMarkerInfoWindowShown(
    MarkerId markerId, {
    required int mapId,
  }) async {
    assert(markerId != null);
    return  (await channel(mapId).invokeMethod<bool>('markers#isInfoWindowShown',
        <String, String>{'markerId': markerId.value}))! ;
  }

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: null-safetySupport for Dart's null safety featurep: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.waiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions