safeToBool static method
将其他类型转换为int
Implementation
static bool safeToBool(dynamic source, {bool def = false}) {
try {
if (source != null) {
if (source is bool) {
return source;
}
String s = source.toString();
if (s == "1" || s == "true" || s == "TURE") {
return true;
}
}
} catch (e) {
//do nothing
}
return def;
}