'Future<http.Response> what if request response was null

I have trying to made global http request class to use it in all my app, I declared method inside class "webPost" to return Future<http.Response> but didn't accept null as return, in case request returns null on any exeption , what should I do in this case .

code :

class TWebRequest{
  
late int errorCode = -1 ; 
late String errorMessage = ""; 
late bool successed = false;


Future<http.Response> webPost(String url , Object? body , Map<String,String> headers ) async
{

  final http.Response response ;
try {
   response =
      await http.post(Uri.parse(url),
          headers: headers ,body:  body);
  return  response;
  
} on SocketException {
  errorCode = 10000 ;
  errorMessage = "SocketException";
} on HttpException {
  errorCode = 10001 ;
  errorMessage = "HttpException";
} on FormatException {
 errorCode = 10002 ;
 errorMessage = "FormatException";
 return null ; //not accept 
}
finally { 
}

} //end void 
} //end class


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source