Skip to content

Instantly share code, notes, and snippets.

@kmkkkp
Created July 10, 2023 07:08
Show Gist options
  • Save kmkkkp/041c4e9f7b1a8bf1395c53c48399b020 to your computer and use it in GitHub Desktop.
Save kmkkkp/041c4e9f7b1a8bf1395c53c48399b020 to your computer and use it in GitHub Desktop.
class_practice_NamedConctructor

class_practice_NamedConctructor

Created with <3 with dartpad.dev.

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