fetchDeeplinkData static method

Future<NiceDeeplinksData> fetchDeeplinkData(
  1. String link
)

Implementation

static Future<NiceDeeplinksData> fetchDeeplinkData(String link) async {
  if (_apiKey == null) {
    throw StateError("NiceDeeplinks not initialized. Call NiceDeeplinks.initialize() first.");
  }

  final parts = link.replaceAll("https://", "").split("/");
  final domain = parts.first;
  final code = parts.last;
  final uri = Uri.parse("$_baseUrl/dynamic-link/$code?domain=$domain");
  final response = await http.get(
    uri,
    headers: {
      "Api-Key": _apiKey!,
      "Tenant-Id": _tenantId!,
    },
  );
  if (response.statusCode >= 200 && response.statusCode < 300) {
    final data = jsonDecode(response.body) as Map<String, dynamic>;
    return NiceDeeplinksData(link: Uri.parse((data["deepLinkUrl"] as String).replaceFirst("/#", "")));
  } else {
    throw Exception("Failed to fetch deeplink data");
  }
}