launch method

  1. @override
Future<void> launch(
  1. String url, {
  2. String? androidPackageName,
})
override

Launch a URL. Opens in the native app if it handles the URL, otherwise opens in the default browser.

On Android, androidPackageName targets the specific app package so the system resolver doesn't open a different app (e.g. Go vs Maps). Complete only once handoff is accepted. Throw MapHandoffException only for confirmed rejection; other exceptions stop fallback because the outcome is unknown. A blocked popup must be marked blocked, not retried.

Implementation

@override
Future<void> launch(String url, {String? androidPackageName}) async {
  try {
    await methodChannel.invokeMethod('launch', {
      'url': url,
      'packageName': ?androidPackageName,
    });
  } on PlatformException catch (error) {
    if (error.code == 'LAUNCH_REJECTED') {
      throw const MapHandoffException(
        'The operating system rejected the map URL.',
      );
    }
    rethrow;
  }
}