如何在 dart 中编写 If 语句?

How to write If statement in dart?

我正在写这样的 if 语句:

String value;
if(int.parse(value)) // I want to write a condition that if error appear while parsing 
// (like value contains some strings) then if statement run

可以写成try/catch

try{ 
int.parse(value)
}
catch (e) {
// implement if statement
}

但我想用 if 语句来做这个

那么你可以尝试使用 tryParse() method 的不同方法并检查结果是否 null 然后解析失败。

if (int.tryParse(value)==null){ // execute failed parse code }