ConvertUrl constructor

ConvertUrl(
  1. String getUrl
)

Constructs a ConvertUrl object. getUrl is the URL to be converted.

Implementation

ConvertUrl(String getUrl) {
  url = getUrl;

  List<String> splitUrl = url.replaceFirst(RegExp(r'://'), ' ').split(' ');
  appScheme = splitUrl[0];

  if (Platform.isAndroid) {
    if (isAppLink()) {
      if (appScheme!.contains('intent')) {
        List<String> intentUrl = splitUrl[1].split('#Intent;');
        String host = intentUrl[0];
        if (host.contains(':')) {
          host = host.replaceAll(RegExp(r':'), '%3A');
        }
        List<String> arguments = intentUrl[1].split(';');

        if (appScheme! != 'intent') {
          appScheme = appScheme!.split(':')[1];
          appLink = '${this.appScheme!}://$host';
        }
        for (var s in arguments) {
          if (s.startsWith('package')) {
            String package = s.split('=')[1];
            this.package = package;
          } else if (s.startsWith('scheme')) {
            String scheme = s.split('=')[1];
            appLink = '$scheme://$host';
            appScheme = scheme;
          }
        }
      } else {
        appLink = url;
      }
    } else {
      appLink = url;
    }
  } else if (Platform.isIOS) {
    appLink = appScheme == 'itmss' ? 'https://${splitUrl[1]}' : url;
  }
}