launch method

  1. @override
Future<LinkLaunchResponse> launch([
  1. Subject? input
])
override

Launches this app, and returns the appropriate launch response

Implementation

@override
Future<LinkLaunchResponse> launch([Subject? input]) async {
  final log = Logger('links.$provider');
  final handle = input?.handle;
  if (input == null || handle == null) {
    return LinkLaunchResponse.invalidInput();
  } else {
    var isHttp = handle.startsWith(_httpPrefixPattern);
    final generator = this;

    var appLink = generator.appLinkGenerator?.call(input).toString();
    if (!isHttp && appLink != null && await url.canLaunch(appLink)) {
      log.info('Attempt app link: $appLink');
      final nativeAppLaunchSucceeded =
          await url.launch(appLink, statusBarBrightness: Brightness.light);
      log.info('success: $nativeAppLaunchSucceeded for app launch $appLink');
      if (nativeAppLaunchSucceeded == true) {
        return LinkLaunchResponse.openedApp();
      }
      if (nativeAppLaunchSucceeded != true &&
          generator.webLinkGenerator != null) {
        log.info(
            'Native launch for $provider -> $handle failed.  Attempting web launch');
        final webLink = generator.webLinkGenerator!(input).toString();
        final response = await url.launch(webLink, forceSafariVC: true);
        log.info('success: $response for web launch $webLink');
        return response
            ? LinkLaunchResponse(LaunchResult.openedWeb)
            : LinkLaunchResponse.unsupported();
      } else if (nativeAppLaunchSucceeded != true) {
        log.info(
            "Native app navigation failed for $provider: $handle, and this provider doesn't support web links");
        return LinkLaunchResponse.unsupported();
      }
    } else if (isHttp || generator.webLinkGenerator != null) {
      log.info(
          'App cannot launch $provider native links, using web link for  $handle');
      final webLink =
          isHttp ? handle : generator.webLinkGenerator!(input).toString();
      final webLinkResult = await url.launch(webLink, forceSafariVC: true);
      return webLinkResult
          ? LinkLaunchResponse(LaunchResult.openedWeb)
          : LinkLaunchResponse.unsupported();
    } else {
      log.warning(
          "App can't launch $provider links and no web link could be produced for $handle");
      return LinkLaunchResponse.unsupported();
    }
    return LinkLaunchResponse.unsupported();
  }
}