问题遇到的现象和发生背景
前端用的是flutter,使用dio的get请求,加了connecttimeout后出现Bad state: Future already completed,但是能成功拿到数据,有大佬知道是什么问题吗?
问题相关代码,请勿粘贴截图
前端
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
loadData();
}
void loadData() async {
try {
Dio dio = Dio();
dio.options.connectTimeout = 5000;
dio.options.receiveTimeout = 5000;
dio.get('http://127.0.0.1:5000').then((value) => {print(value.data)});
} catch (e) {
print(Fluttertoast.showToast(msg: e.toString()));
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
"/": (context) => const HomePage(),
},
);
}
}
服务器端
app = Flask(__name__)
CORS(app)
@app.route('/')
def demo():
return '123'
运行结果及报错内容
123
Error: Bad state: Future already completed
at Object.throw_ [as throw] (http://localhost:49846/dart_sdk.js:5080:11)
at _AsyncCompleter.new.completeError (http://localhost:49846/dart_sdk.js:35274:51)
at http://localhost:49846/packages/dio/src/interceptors/log.dart.lib.js:651:25
at _RootZone.runUnary (http://localhost:49846/dart_sdk.js:40511:59)
at _FutureListener.then.handleValue (http://localhost:49846/dart_sdk.js:35438:29)
at handleValueCallback (http://localhost:49846/dart_sdk.js:35999:49)
at Function._propagateToListeners (http://localhost:49846/dart_sdk.js:36037:17)
at _Future.new.[_complete] (http://localhost:49846/dart_sdk.js:35864:25)
at http://localhost:49846/dart_sdk.js:34994:30
at internalCallback (http://localhost:49846/dart_sdk.js:26685:11)