객체 속성 변경 시 객체 변수를 계속 사용해야하는 걸

class Player{
  String? name;
  int? xp, age;
  String? team;
  

  Player({required this.name, required this.xp, required this.team});
  
  void display(){
    print("Hi My name is $name");
  }
}


void main(){
  var nico = Player(name: "nico", xp: 1200, team: "red")
  ..name = "las"
  ..xp =1200
  ..team = "blue"
  ..display();
  
  var potato = nico
    ..name="zzz"
    ..xp=1233
    ..team="red"
    ..display();
}


#출력
Hi My name is las
Hi My name is zzz

.. 으로 대체

 

'DART&Flutter' 카테고리의 다른 글

Dart) mixin  (0) 2026.05.19
Dart) 오버라이딩  (0) 2026.05.19
Dart) 이름있는 생성자(Named Constructors)  (0) 2026.05.19
Dart) 클래스 생성자 및 Named Parameters  (0) 2026.05.18
Dart) final vs const  (2) 2026.05.15

+ Recent posts