onInit method
Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.
Implementation
@override
Future<void> onInit() async {
HttpOverrides.global = MyHttpOverrides();
try {
allowAutoSignedCert = allowAutoSignedCertificate;
httpClient
..baseUrl = baseURL
..errorSafety = true
..followRedirects = allowFollowRedirects
..timeout = maxTimeOut ?? 15.seconds
..maxAuthRetries = maxAuthRetry
..maxRedirects = maxRedirectURL
..sendUserAgent = useUserAgent
..userAgent = customUserAgent;
/// add something on every http request
if (interceptorAddRequestModifier != null) {
httpClient.addRequestModifier<void>((request) async {
interceptorAddRequestModifier?.call(request);
return request;
});
}
/// if (401) -> AUTO REFRESH TOKEN
if (interceptorAddAuthenticator != null) {
httpClient.addAuthenticator<void>((request) async {
interceptorAddAuthenticator?.call(request);
return request;
});
}
/// add something on every http request
if (interceptorAddResponseModifier != null) {
httpClient.addResponseModifier((request, response) {
interceptorAddResponseModifier?.call(request, response);
return response;
});
}
} on Exception {
throw ApiException('''
Please Init & Inject ExHttp on main program
== EXAMPLE ==
Get.put(
ExHttp(
baseURL: 'https://api.com',
baseHeader: {},
maxTimeOut: 30.seconds,
maxAuthRetry: 5,
allowFollowRedirects: true,
showLogHeader: false,
showLogResponse: false,
),
);
''');
}
super.onInit();
}