调用返回。flutter: Instance of 'Future<dynamic>'
来源:4-4 登录态保持与接口鉴权处理

梦94
2021-10-04
Future fire(BaseRequest request) async {
HiNetResponse? response;
var error;
try{
response = await send(request);
} on HiNetError catch(e){
error=e;
response=e.data;
printLog(e.message);
}catch(e){
//其他异常
error = e;
printLog(e);
}
if(response == null){
printLog("error:$error");
}
var result = response?.data;
printLog("result:$result");
var status = response?.statusCode;
switch(status){
case 200:
return result;
case 401:
throw NeedLogin();
case 403:
throw NeedAuth(result.toString(),data: result);
default:
throw HiNetError(status ?? -1, result.toString(),data: result);
}
}
写回答
2回答
-
CrazyCodeBoy
2022-09-09
因为HiNet.getInstance().fire
返回的是个future,通过then的方式可以获取future执行的结果。
00 -
梦94
提问者
2021-10-04
var notice = HiNet.getInstance().fire(NoticeRequest()); notice.then((value) => { print("成功: ${value.toString()}") });
改成这好了,为何?
01
相似问题