Created
June 29, 2021 07:15
-
-
Save bernbecht/6cde6e080d7193cda2285d937ac846b9 to your computer and use it in GitHub Desktop.
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
class Person { | |
// String and int variables don't allow `null` | |
// They wanna be initialized | |
// `late` says to compiler to not worry as these vars will be init later | |
late String name; | |
late int age; | |
// constructor with named parameters, with default values | |
Person({String inputName = '', int age = 30}) { | |
name = inputName; | |
// if parameter and class field has same name, you need to use `this.` | |
this.age = age; | |
} | |
// constructor with sequence parameters | |
// Person(String inputName, int inputAge) { | |
// this.name = inputName; | |
// this.age =age | |
// } | |
// short hand constructor | |
// Person({this.name, this.age = 30}); | |
} | |
void main () { | |
var p1 = Person(inputName: 'Max', age: 31); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment