Skip to content

Instantly share code, notes, and snippets.

@ezura
Last active May 20, 2018 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezura/31606b48969a61ba3856fb0fa0620760 to your computer and use it in GitHub Desktop.
Save ezura/31606b48969a61ba3856fb0fa0620760 to your computer and use it in GitHub Desktop.
void main() {
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
for (var i in ["1", false]) {
print(convertToBool(i));
}
}
bool convertToBool(dynamic arg) {
print(arg.runtimeType);
if (arg is bool) return arg;
if (arg is String) return arg == 'true';
// dynamic is like `NSObject`??
return arg == 1;
// info: dead code
// -> checking control flow??
throw new ArgumentError('Cannot convert $arg to a bool.');
}
// bool convertToBool(int arg) {
// print(arg.runtimeType);
// return true;
// }
// bool convertToBool(String arg) {
// print(arg.runtimeType);
// return false;
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment