getRequest method
Sends a GET request to the specified URL and returns the response
Implementation
Future<dynamic> getRequest(String url, [Map<String, String>? header]) async {
var val = await ConnectivityService().checkConnectivity();
if (val) {
return http
.get(Uri.parse(url), headers: header)
.then((http.Response response) {
final statusCode = response.statusCode;
if (statusCode == 200) {
return {
'status': true,
'body': utf8.decode(response.bodyBytes),
'message': 'success',
'header': response.headers,
'code': statusCode,
};
} else {
return {
'status': false,
'body': response.body,
'message': (response.statusCode == 404)
? 'Page not Found'
: (response.statusCode == 401)
? 'Unauthorized'
: 'Error occured while Fetching Data',
'header': response.headers,
'code': statusCode,
};
}
});
} else {
return {
'status': false,
'message': 'No Internet',
};
}
}