getInstalledMaps method

  1. @override
Future<Set<String>> getInstalledMaps(
  1. List<MapApp> maps
)
override

Returns the ids of maps (from maps) that have native apps installed.

The probing payload (URL schemes on iOS, package names on Android) is derived from each MapApp and sent to the native side. No map knowledge is hardcoded in native code.

Returns an empty set on platforms that don't support app detection.

Implementation

@override
Future<Set<String>> getInstalledMaps(List<MapApp> maps) async {
  // Build probe payload: id → scheme (iOS) or id → package (Android).
  final probes = <String, String>{
    for (final m in maps)
      if (platform == MapPlatform.ios && m.iosScheme != null)
        m.id: m.iosScheme!
      else if (platform == MapPlatform.android && m.playStoreId != null)
        m.id: m.playStoreId!,
  };

  final result = await methodChannel.invokeMethod('getInstalledMaps', probes);
  final installed = <String>{};
  if (result is Map) {
    final installedIds = result['installed'];
    if (installedIds is List) {
      installed.addAll(installedIds.cast<String>());
    }
    final undeclaredIds = result['undeclared'];
    if (undeclaredIds is List) {
      _warnUndeclaredSchemes(undeclaredIds.cast<String>(), maps);
    }
  }

  // Add maps that need no probe (e.g. Apple Maps on iOS).
  if (platform != null) {
    for (final m in maps) {
      if (m.isAlwaysAvailable(platform!)) installed.add(m.id);
    }
  }

  return installed;
}