Skip to content

Instantly share code, notes, and snippets.

@Chralu
Last active September 21, 2022 14:21
Show Gist options
  • Save Chralu/bdebc6ad1f765990596c6cc2d321117f to your computer and use it in GitHub Desktop.
Save Chralu/bdebc6ad1f765990596c6cc2d321117f to your computer and use it in GitHub Desktop.
Flutter101 - Class getter

Flutter101 - Class getter

Created with <3 with dartpad.dev.

class Person {
static const daysInYear = 365;
final String firstname;
final String lastname;
final double? weight;
final DateTime birthdate;
Person({
required this.firstname,
required this.lastname,
required this.birthdate,
this.weight,
});
// accesseur
int get age => (DateTime.now().difference(birthdate).inDays / daysInYear).round();
}
void main() {
final johnDoe = Person(
firstname: "John",
lastname: "Doe",
birthdate: DateTime(1950, 07, 12),
);
print(johnDoe.age);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment