request method
Implementation
Future<Response?> request({
required String url,
required String method,
Map<String, dynamic>? body,
Map<String, dynamic>? headers,
Options? options,
}) async {
try {
headers = headers ?? {};
options = options ?? Options(headers: headers);
List<String>? savedCookies = await sessionManager?.getSessionCookies();
if (savedCookies!.isNotEmpty) {
headers['Cookie'] = savedCookies.join('; ');
}
Response response;
switch (method.toUpperCase()) {
case 'POST':
response = await _dio.post(url, data: body, options: options);
break;
case 'GET':
response = await _dio.get(url, options: options);
break;
case 'PUT':
response = await _dio.put(url, data: body, options: options);
break;
case 'PATCH':
response = await _dio.patch(url, data: body, options: options);
break;
case 'DELETE':
response = await _dio.delete(url, data: body, options: options);
break;
default:
throw UnsupportedError("Method not supported: $method");
}
_storeResponseCookies(response);
return response;
} catch (e) {
if (kDebugMode) {
print("Error during network request: $e");
}
return null;
}
}