I have defined a function to get some information from the server
@override
Future<HttpResponse<dynamic>> getAppInfo() async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
final _result = await _dio.fetch(_setStreamType<HttpResponse<dynamic>>(
Options(method: 'GET', headers: <String, dynamic>{}, extra: _extra)
.compose(_dio.options, '/user/app-info',
queryParameters: queryParameters, data: _data)
.copyWith(baseUrl: baseUrl ?? _dio.options.baseUrl)));
final value = _result.data;
final httpResponse = HttpResponse(value, _result);
return httpResponse;
}
I am passing this function as an argument at run time to different function. Another function is defined this way
Future<HttpResponse?> handleApi(
Function function, [
List<dynamic>? args,
]) async {
try {
final HttpResponse httpResult = await Function.apply(
function,
args,
) as HttpResponse; // This following bloc of code is not getting called
if (httpResult.response.statusCode == HttpStatus.ok ||
httpResult.response.statusCode == HttpStatus.created) {
return httpResult;
}
} on Exception catch (e) {
return null;
}
}
And i am passing first function to second function as an argument. It was working fine without null safe version of flutter. And after the migration to null safe, the call is not happening on the function at run time.
I am calling handleApi fucntion following way
final httpResultOrError = await _apiCallHandler.handleApi(
getAppInfo,
);