launchApp method

Future<bool> launchApp({
  1. LaunchMode mode = LaunchMode.externalApplication,
})

Attempts to launch the application using the converted URL. If the application cannot be launched, it tries to open the application in the corresponding app market (Google Play for Android, App Store for iOS).

Implementation

Future<bool> launchApp({LaunchMode mode = LaunchMode.externalApplication}) async {
  if (Platform.isAndroid) {
    try {
      return await launchUrlString((await getAppLink())!, mode: mode);
    } catch (e) {
      return await launchUrlString((await getMarketUrl())!, mode: mode);
    }
  } else if (Platform.isIOS) {
    final appLink = await getAppLink();
    if (appLink != null) {
      try {
        if (await launchUrlString(appLink)) return true;
      } catch (e) {
        // pass
      }
    }

    final marketUrl = await getMarketUrl();
    if (marketUrl != null) {
      try {
        return await launchUrlString(marketUrl);
      } catch (e) {
        // pass
      }
    }
  }
  return false;
}