'Error: A value of type 'RequestOptions' can't be assigned to a variable of type 'Future<dynamic>'
I got below error when I compiling a flutter project downloaded from github .
here is the code:
import 'package:dio/dio.dart';
class HeaderInterceptors extends InterceptorsWrapper {
@override
onRequest(RequestOptions options) {
// 超时
options.connectTimeout = 15000;
return options;
}
}
and here is the mistake :
lib/common/service/interceptors/header_interceptor.dart:8:12: Error: A value of type 'RequestOptions' can't be assigned to a variable of type 'Future<dynamic>'.
- 'RequestOptions' is from 'package:dio/src/options.dart' ('/D:/intellij/flutter_windows_1.22.5-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/dio-3.0.10/lib/src/options.dart').
- 'Future' is from 'dart:async'.
return options;
^
any idea?
Solution 1:[1]
InterceptorsWrapper.onRequest() is a void. To modify connectionTimeout
, you can call RequestInterceptorHandler.next(RequestOptions)
to update the config.
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
options.connectTimeout = 15000;
handler.next(options);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Omatt |