im calling a get response in Dio with my api,but i keep getting this error "'FutureOr<Response>', is a potentially non-nullable type." althoug i have returned a return statement in my get api function.
i add a return statement to it and im now tempted to downgrade flutter to help but before i do that i want to solve the issue first.
`
//finction for sending get request in the api
//error apears here on the get
Future<Response> get(String _path, {Map<String, dynamic>? query}) async {
try {
String _url = '$_base_url$_path';
Map<String, dynamic> _query = {
'api_key': _api_key,
'language': 'english',
};
if (query != null) {
_query.addAll(query);
}
return await dio.get(
_url,
queryParameters: _query,
);
} on DioError catch (e) {
print('Unable to perform get request.');
print('DioError: $e');
}
}
`
CodePudding user response:
You can think about this way. While the try
blocks raise some issue, it will fail to return the response object.catch block is not returning anything.You can return error Reposone object here or just change return datatyoe to nullable Response.
Future<Response?> get(
While using this method, do a null check.
final result = await get(...);
if(result !=null){...}
For FutureBuilder, use nullable dateType.
CodePudding user response:
so after quite the number of research.what i had to do was to return the response.
return Response();