launchRedirect method

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

Implementation

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

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