Skip to content

Instantly share code, notes, and snippets.

@erluxman
Created April 17, 2020 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erluxman/76922028eccb4535f0cdddc8e4b17aa1 to your computer and use it in GitHub Desktop.
Save erluxman/76922028eccb4535f0cdddc8e4b17aa1 to your computer and use it in GitHub Desktop.
Fat arrow functions usage
void main() {
User()
..firstName = "Laxman"
..lastName = " Bhattarai"
..age = 18
..printUser();
}
class User {
String firstName;
String lastName;
DateTime birthday;
String get fullName => firstName + lastName;
set age(int age) =>
birthday = DateTime.now().subtract(Duration(days: age * 365));
int get age => DateTime.now().year - birthday.year;
bool get isAdult => age >= 18;
printUser() => print(fullName + " is a ${isAdult ? "Adult" : "Child"}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment