Skip to content

Instantly share code, notes, and snippets.

@AbdullohBahromjonov
Last active April 27, 2022 17:08
Show Gist options
  • Save AbdullohBahromjonov/0966a8fabc4b8bbfd4990c89884d660e to your computer and use it in GitHub Desktop.
Save AbdullohBahromjonov/0966a8fabc4b8bbfd4990c89884d660e to your computer and use it in GitHub Desktop.
Parsing one data type to another
void main() {
//final one = int.parse('one'); //error
final two = double.parse('2.2'); //successful
final three = int.tryParse('one'); //null
final four = double.tryParse('4.5'); //successful
final one = int.parse('3');
print('''
$two
$three
$four
''');
print(parsingInteger(one));
}
int parsingInteger(Object n) {
return n as int;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment