Skip to content

Instantly share code, notes, and snippets.

@Chralu
Last active September 21, 2022 12:43
Show Gist options
  • Save Chralu/2b6bc99899c223a6ba331c91bc47e0b4 to your computer and use it in GitHub Desktop.
Save Chralu/2b6bc99899c223a6ba331c91bc47e0b4 to your computer and use it in GitHub Desktop.
Flutter101 - Class simple

Flutter101 - Class simple

Created with <3 with dartpad.dev.

class Person {
final String firstname;
final String lastname;
final double? weight;
// Constructeur avec des paramètres
// nommés.
Person({
required this.firstname,
required this.lastname,
this.weight,
});
// On peut aussi utiliser
// des paramètres positionnés
// Person(
// this.firstname,
// this.lastname,
// this.weight,
// );
// L'annotation `@override` indique qu'il s'agit d'une
// surcharge de méthode.
@override
String toString() {
if (weight == null) return "$firstname $lastname";
return "$firstname $lastname ($weight kg)";
}
}
void main() {
final johnDoe = Person(
firstname: "John",
lastname: "Doe",
);
print(johnDoe);
final johnnyBegood = Person(
firstname: "Johnny",
lastname: "Begood",
weight: 70,
);
print(johnnyBegood);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment