openApp static method

Future<int> openApp({
  1. String? iosUrlScheme,
  2. String? androidPackageName,
  3. String? appStoreLink,
  4. bool? openStore,
})

Function to launch the external app or redirect to store

Implementation

static Future<int> openApp(
    {String? iosUrlScheme,
    String? androidPackageName,
    String? appStoreLink,
    bool? openStore}) async {
  String? packageName = Platform.isIOS ? iosUrlScheme : androidPackageName;
  String packageVariableName =
      Platform.isIOS ? 'iosUrlScheme' : 'androidPackageName';
  if (packageName == null || packageName == "") {
    throw Exception('The $packageVariableName can not be empty');
  }
  if (Platform.isIOS && appStoreLink == null && openStore != false) {
    openStore = false;
  }

  return await _channel.invokeMethod('openApp', {
    'package_name': packageName,
    'open_store': openStore == false ? "false" : "open it",
    'app_store_link': appStoreLink
  }).then((value) {
    if (value == "app_opened") {
      logCat("app opened successfully");
      return 1;
    } else {
      if (value == "navigated_to_store") {
        if (Platform.isIOS) {
          logCat(
              "Redirecting to AppStore as the app is not present on the device");
        } else {
          logCat(
              "Redirecting to Google Play Store as the app is not present on the device");
        }
      } else {
        logCat(value);
      }
      return 0;
    }
  });
}