Created
April 17, 2020 02:52
-
-
Save erluxman/76922028eccb4535f0cdddc8e4b17aa1 to your computer and use it in GitHub Desktop.
Fat arrow functions usage
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
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