Created with <3 with dartpad.dev.
Created
July 10, 2023 07:08
-
-
Save kmkkkp/041c4e9f7b1a8bf1395c53c48399b020 to your computer and use it in GitHub Desktop.
class_practice_NamedConctructor
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 Player { | |
final String name; | |
int xp, age; | |
String team; | |
Player({ | |
required this.name, | |
required this.xp, | |
required this.age, | |
required this.team, | |
}); | |
Player.createBluePlayer({ | |
required String name, | |
required int age, | |
}) : this.age = age, | |
this.name = name, | |
xp = 0, | |
team = 'blue'; | |
Player.createRedPlayer({ | |
required String name, | |
required int age, | |
}) : this.age = age, | |
this.name = name, | |
xp = 0, | |
team = 'red'; | |
void sayHello(){ | |
print("Hi my name $name"); | |
} | |
} | |
void main(){ | |
var player1 = Player.createRedPlayer(name:"nico", age:14); | |
player1.sayHello(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment