fetchSdkConfig function
Implementation
Future<SdkConfig> fetchSdkConfig(String token) async {
try {
Debug.print("FetchSdkRequest: Fetching sdk config");
final sdkType = PerceptFlutterPlatform.instance.getSdkType();
final body = jsonEncode({'token': token, 'type': sdkType});
final request = http.post(
Uri.parse(fetchSdkConfigUrl),
headers: await getAuthHeaders(token),
body: body,
);
final response = await request;
Debug.print("FetchSdkRequest Response: ${response.body}");
if (response.statusCode != 200) throw (response.statusCode);
final configJson = jsonDecode(response.body) as Map<String, dynamic>;
return SdkConfig.fromJson(configJson);
} catch (error) {
Debug.print('FetchSdkRequest: Failed to fetch sdk config: $error');
return SdkConfig.defaultConfig;
}
}