onInit method

  1. @override
void onInit()
override

GetConnect Init

Implementation

@override
void onInit() async {
  _baseUrl = baseUrl;
  if (_baseUrl == "" || _baseUrl == "X-Base-Api-Url-With-Forward-Slash") {
    _baseUrl = GetStorage().read("baseUrl") ?? "";
    debugPrint("Base Url >> ${GetStorage().read("baseUrl")}");
    (_baseUrl == "" || _baseUrl == "X-Base-Api-Url-With-Forward-Slash")
        ? throw UnimplementedError(
            "Set the Base url in GetStorage with 'baseUrl' key or setup app_string with 'baseUrl' ")
        : "";
  }

  _debugLog('Initializing ApiService');
  _debugLog('Base URL: $_baseUrl');
  _debugLog('Show SnackBar: $_showSnackBar');
  _debugLog('Show Debug Log: $_showDebugLog');

  showDebugLog(_showDebugLog);
  setDefaultDecoder(httpClient);
  setAuthToken(_headers);
  setApiTimeOut(_defaultTimeoutSeconds);
  setApiMaxRetries(httpClient);
  setApiBearerToken(_headers);
  showSnackbar(_showSnackBar);
  httpClient.baseUrl = _baseUrl;
  httpClient.timeout = Duration(seconds: _defaultTimeoutSeconds);

  _debugLog('Timeout set to: $_defaultTimeoutSeconds seconds');
  _debugLog('Headers: $_headers');

  httpClient.addResponseModifier((request, response) async {
    _showDebugLog
        ? debugPrint("$tag >> Response >> ${(response.bodyString)}",
            wrapWidth: 1024)
        : "";
    return response;
  });
}