readPreferences method

Future<Preferences> readPreferences({
  1. String? realmId,
  2. String? authToken,
})

Retrieves the Preferences details for the specified company.

Implementation

Future<Preferences> readPreferences({
  String? realmId,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.access_token;
  realmId ??= authenticationService.getCachedRealmId();

  Map<String, String> headers = {
    "Authorization": "Bearer ${authToken ?? ""}",
    //'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',

  };

  Map<String, String> params = {
    "minorversion": minorVersion.toString()
  };


  Uri endpoint = Uri.https(
      baseUrl, "/v3/company/$realmId/preferences", params);

  //print (endpoint.toString());

  var response = await
  http.get(endpoint, headers: headers);

  if (response.statusCode == 200) {
    //print (jsonDecode(response.body));
    return Preferences.fromJson(jsonDecode(response.body)["Preferences"]);
  }
  else {
    throw PreferencesException(statusCode: response.statusCode, message: response.body);
  }
}