Skip to content

Instantly share code, notes, and snippets.

@Chralu
Last active September 19, 2022 14:29
Show Gist options
  • Save Chralu/fb73c8fabc9cd0c9597ebc66d1900eb5 to your computer and use it in GitHub Desktop.
Save Chralu/fb73c8fabc9cd0c9597ebc66d1900eb5 to your computer and use it in GitHub Desktop.
Flutter101 - Positioned parameter

Flutter101 - Positioned parameter

Created with <3 with dartpad.dev.

// 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