launchRedirect static method

Future<void> launchRedirect({
  1. Uri? nativeUri,
  2. Uri? universalUri,
})

Implementation

static Future<void> launchRedirect({
  Uri? nativeUri,
  Uri? universalUri,
}) async {
  LoggerUtil.logger.i(
    'Navigating deep links. Native: ${nativeUri.toString()}, Universal: ${universalUri.toString()}',
  );
  LoggerUtil.logger.i(
    'Deep Link Query Params. Native: ${nativeUri?.queryParameters}, Universal: ${universalUri?.queryParameters}',
  );

  // Launch the link
  if (nativeUri != null && await canLaunchUrl(nativeUri)) {
    LoggerUtil.logger.v(
      'Navigating deep links. Launching native URI.',
    );
    try {
      await launchUrl(nativeUri);
    } catch (e) {
      LoggerUtil.logger.i(
        'Navigating deep links. Launching native failed, launching universal URI.',
      );
      // Fallback to universal link
      if (universalUri != null && await canLaunchUrl(universalUri)) {
        await launchUrl(
          universalUri,
          mode: LaunchMode.externalApplication,
        );
      } else {
        throw LaunchUrlException('Unable to open the wallet');
      }
    }
  } else if (universalUri != null && await canLaunchUrl(universalUri)) {
    LoggerUtil.logger.i(
      'Navigating deep links. Launching universal URI.',
    );
    await launchUrl(
      universalUri,
      mode: LaunchMode.externalApplication,
    );
  } else {
    throw LaunchUrlException('Unable to open the wallet');
  }
}