如何解决此表达式的类型为“ void”,因此无法使用其值
我已经创建了一种新方法来作为递归使用,我正在创建从API服务器获取刷新令牌背景的功能
void postLogin(LoginRequest loginRequest) async {
_postStream.sink.add(Result<String>.loading("Loading"));
try {
final response = await client.post('$BASE_URL\/$LOGIN_URL',headers: customHeader,body: json.encode(loginRequest));
print(response.body.toString());
if (response.statusCode == 200) {
_postStream.sink.add(Result<LoginResponse>.success(
LoginResponse.fromJson(json.decode(response.body))));
} else if(response.statusCode == 401) {
getAuthUpadate(postLogin(loginRequest));//error is showing at this place
}
else{
_postStream.sink.add(Result.error(REQUEST_ERROR));
}
} catch (error) {
print(error.toString());
_postStream.sink.add(Result.error(INTERNET_ERROR));
}
}
//////////////
我在功能里面尝试了这个功能 不能被允许
getAuthUpadate(Function function()) async {
try{
final response = await client.post('$BASE_URL\/NEW_ACCESS_TOKEN_PATH',body:json.encode('RefreshToken'));
//get the refreshToken from response
String accessToken = response.body.toString();
//store this access token to the data
function();
}
catch (error){
}
}
解决方法
当我在回调方法中传入 insert into gps_points( geom,user_id)
select ST_SetSRID(ST_MakePoint(lng,lat),4326),uid from unnest(string_to_array(rowsaz[1],',')::double precision[],string_to_array(rowsaz[2],string_to_array(rowsaz[3],')::integer[]) as u(lng,lat,uid);
时发生此错误(例如,当函数声明为 void
时调用 function()
。
例如:
void function() { ... }
,
我可以给你一个关于这个问题的想法。
您只是在调用具有返回值void
的函数,并将其作为参数传递给函数getAuthUpdate
。
您可以尝试这样的事情,
getAuthUpadate(Function function,LoginRequest loginRequest) async { }
,并且在postLogin
方法中,您可以尝试这样的操作
else if(response.statusCode == 401) {
getAuthUpadate(postLogin,loginRequest); // Just pass Reference as parameter!
}
最后,是getAuthUpdate
方法的迭代部分,
try{
final response = await client.post('$BASE_URL\/NEW_ACCESS_TOKEN_PATH',headers: customHeader,body:json.encode('RefreshToken'));
//get the refreshToken from response
String accessToken = response.body.toString();
//store this access token to the data
function(loginRequest);
}
catch (error){
}
希望有效!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。