Created with <3 with dartpad.dev.
Last active
September 19, 2022 14:29
-
-
Save Chralu/fb73c8fabc9cd0c9597ebc66d1900eb5 to your computer and use it in GitHub Desktop.
Flutter101 - Positioned parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2022, TheTribe.io | |
String helloWithPositionalParameters( | |
String name, | |
int age, | |
double? size, //le ? indique qu'une valeur [null] est acceptée | |
) { | |
if (size != null) { | |
return "Bonjour $name ($age ans, $size mètres)"; | |
} | |
return "Bonjour $name ($age ans)"; | |
} | |
void main () { | |
// OK | |
print( | |
helloWithPositionalParameters( | |
"John", | |
20, | |
null, | |
) | |
); | |
// OK | |
print( | |
helloWithPositionalParameters( | |
"John", | |
20, | |
1.8, | |
), | |
); | |
// KO : Ne compilerait pas | |
// Les trois paramètres sont obligatoires | |
// print( | |
// helloWithPositionalParameters( | |
// "John", | |
// 20, | |
// ) | |
// ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment