【发布时间】:2018-12-14 10:23:24
【问题描述】:
我正在调用 Web API 并接收 Profile 模型作为响应。当我使用下面的代码时,它会抛出一个错误:
try{
if(profile.message.isEmpty){
Navigator.of(context).pushNamed("/home");
}else if(profile == null){
_showDialog("Please check your internet connection");
}else{
_showDialog("Please enter valid credentials");
}
}catch(exception){
print(exception);
}
【问题讨论】:
-
那是因为
profile.message返回null。你可能想要if(profile?.message?.isEmpty ?? true) -
感谢它为我工作。