I have a method in a class but it is not returning values, is it because I'm passing parameters to the method?
Im trying to make a class and method to do HTTP requests using Dio
class appCommunicate {
appGetRequest(String url, {headers = ''})
async {
if (headers.length > 0) {
_res = await dio.get(url, options: Options(headers: headers));
}
else
{
_res = await dio.get(url);
}
return _res;
}
}
And then when I try to invoke this class as follows:
final communicate = appCommunicate();
final response = await communicate.appGetRequest(_myUrl);
Nothing happens, no communication and the app just stops there
dio.get() is venerable for exception. You must add dio.get code in try catch block to handle exception.
appGetRequest(String url, {headers = ''}) async {
try {
return (headers.length > 0) ? await dio.get(url, options: Options(headers: headers)) : await dio.get(url);
}
catch (e) {
print(e);
}
}