Dio: type 'Future<dynamic>' is not a subtype of type 'Future<Response<dynamic>>'

Created on 27 Apr 2018  ·  9Comments  ·  Source: flutterchina/dio

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type 'Future<dynamic>' is not a subtype of type 'Future<Response<dynamic>>' where
  Future is from dart:async
  Future is from dart:async
  Response is from package:dio/src/Response.dart

#0      Dio._onError (package:dio/src/Dio.dart:526:12)
#1      Dio._makeRequest.<anonymous closure> (package:dio/src/Dio.dart:420:28)
#2      Dio._checkIfNeedEnqueue (package:dio/src/Dio.dart:554:22)
#3      Dio._makeRequest (package:dio/src/Dio.dart:416:35)
<asynchronous suspension>
#4      Dio._request.<anonymous closure> (package:dio/src/Dio.dart:316:16)
#5      Dio._checkIfNeedEnqueue (package:dio/src/Dio.dart:554:22)
#6      Dio._request (package:dio/src/Dio.dart:287:31)
<asynchronous suspension>
#7      Dio.request (package:dio/src/Dio.dart:270:12)
<asynchronous suspension>
#8      Dio.get (package:dio/src/Dio.dart:62:12)
#9      UserApi.getUser (package:saytoken_flutter/api/user_api.dart:12:31)
<asynchronous suspension>
#10     _LoginPageState.login (package:<…>
[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
DioError [DioErrorType.DEFAULT]: type 'Future<dynamic>' is not a subtype of type 'Future<Response<dynamic>>' where
  Future is from dart:async
  Future is from dart:async
  Response is from package:dio/src/Response.dart
#0      Dio.resolve (package:dio/src/Dio.dart:112:21)
#1      Dio._onSuccess (package:dio/src/Dio.dart:509:18)
#2      Dio._makeRequest.<anonymous closure> (package:dio/src/Dio.dart:398:57)
#3      Dio._checkIfNeedEnqueue (package:dio/src/Dio.dart:554:22)
#4      Dio._makeRequest (package:dio/src/Dio.dart:393:33)
<asynchronous suspension>
#5      Dio._request.<anonymous closure> (package:dio/src/Dio.dart:316:16)
#6      Dio._checkIfNeedEnqueue (package:dio/src/Dio.dart:554:22)
#7      Dio._request (package:dio/src/Dio.dart:287:31)
<asynchronous suspension>
#8      Dio.request (package:dio/src/Dio.dart:270:12)
<asynchronous suspension>
#9      Dio.get (package:dio/src/Dio.dart:62:12)
#10     UserApi.getUser (package:saytoken_flutter/ap<…>

Most helpful comment

get same error while calling dio.delete with lates dio package.

An error occurred. type 'Future<Response<dynamic>>' is not a subtype of type 'Response<dynamic>'

All 9 comments

已修复,请升级到0.0.9重试.

Hi, @wendux
I meet this issue with version 0.1.3, when I call dio.download method.
env:

  • dio: ^0.1.3
  • Flutter: Channel beta, v0.5.1

but version 0.0.14 works fine.

@Yaxian fixed, please update to 0.1.4 and try again.

在2.1.7版本中,使用lock并且使用泛型response则会导致类型不匹配错误,初步原因:
image
在980行enqueue这个函数并没有声明泛型类型。
image

@wendux 请查看下

I get this exception by simply returning: .catchError((error, stackTrace) => Future.error(error, stackTrace)).

get same error while calling dio.delete with lates dio package.

An error occurred. type 'Future<Response<dynamic>>' is not a subtype of type 'Response<dynamic>'

I was getting this error too, right after adding token refresh InterceptorsWrapper. I noticed that this error occurs when Dio is locked.

An error occurred. type 'Future<Response<dynamic>>' is not a subtype of type 'Response<dynamic>'

In order to fix it, I changed the signature of _dispatchRequest method inside Dio.dart from

FutureOr<Response<T>> _dispatchRequest<T>(RequestOptions options)

to

FutureOr _dispatchRequest<T>(RequestOptions options)

P.S. I have no idea what I'm doing :(

this error happens again in latest version of dio (v.3.0.10)

Was this page helpful?
0 / 5 - 0 ratings