简体   繁体   中英

How to write If statement in dart?

I am writing if statement like that:

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

It can be achieved by writing try/catch

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

But I want to do this with if statement

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM