我正在尝试将对象与用户输入的字符串进行比较。该对象来自我映射的 json api 响应。我在“if”上收到错误:
MaterialButton(
child: Text("Connect"),
textColor: Colors.black,
onPressed: (){
fetchUser().then((user)=> (if user.username == username){
return Get.toNamed('/home');
});
},
color: Colors.grey[350],
)
Run Code Online (Sandbox Code Playgroud)
这是函数
Future <User>fetchUser() async{
var authresponse = await http.get(userCall);
if (authresponse.statusCode == 200){
var jsondata = jsonDecode(authresponse.body);
final data = apicallFromJson(jsondata);
var user = data.subsonicResponse.user;
return user;
}else{
throw Exception("Unable to connect to server, try again");}
}
``
Run Code Online (Sandbox Code Playgroud)