Dio HTTP 5.0.4 compatibility issue: "Response<dynamic>" not assignable to "Response<Map<String, dynamic>>"

39 Views Asked by At

I'm facing a compatibility issue after upgrading Dio to version 5.3.3 and Dio HTTP to version 5.0.4 in my Flutter project. The specific error message is:

Code:

The argument type 'Response<Map<String, dynamic>>' can't be assigned to the parameter type 'Response<dynamic>'.

enter image description here

This issue arises when trying to create an HttpResponse object in a Retrofit-like setup. The relevant code snippet looks like this:

// Your function code
@override
Future<HttpResponse<LoginResponseEntity>> loginUser(loginUserRequest) async {
    const _extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final _data = <String, dynamic>{};
    _data.addAll(loginUserRequest.toJson());

    final Response<dynamic> _result = await _dio.fetch(
        Options(
            method: 'POST',
            headers: <String, dynamic>{},
            extra: _extra,
        )
            .compose(
            _dio.options,
            '/api/Auth/Login',
            queryParameters: queryParameters,
            data: _data,
        )
            .copyWith(baseUrl: baseUrl ?? _dio.options.baseUrl),
    );

    final value = LoginResponseEntity.fromJson(_result.data!);
    final httpResponse = HttpResponse<LoginResponseEntity>(value, _result as Response<Map<String, dynamic>>);
    return httpResponse;
}

Additional Information:

Dio Version: 5.3.3 Dio HTTP Version: 5.0.4 Retrofit Version: ^2.0.0 Flutter Version: [Channel stable, 3.3.10]

Upgrade Dio to version 5.3.3 and Dio HTTP to version 5.0.4. Implement a function similar to the provided code snippet. Encounter the error mentioned above. Expected Behavior: Expect the code to be compatible with Dio 5.3.3 and Dio HTTP 5.0.4 without the mentioned type mismatch issue.

Research: I've tried [any steps you've taken to troubleshoot the issue or any resources you've consulted].

0

There are 0 best solutions below