'Flutter error The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type
I got this error. When my Future method not return anything when in else. I don't know how to return Future data in else statement.
"The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type."
This is my method to connect with API.
static Future<TestingResponse> getTestingDataResp(BuildContext context) async{
Future<TestingResponse> testingResponse;
//todo call real api
var _api = await BaseNetworkRequest.noAuthRequest(context);
String _path = "XXXXXXXXXXXXXX";
response = await _api!.get(_path);
var dataResp = TestingResponse.fromJson(response!.data);
if(response!.statusMessage == 'success'){
print(dataResp.data);
}
else{
return testingResponse;
}
}
In this method, how to return Future type in else statement?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
