Dart Multiple Constructors

后端 未结 7 1664
一向
一向 2021-02-03 16:51

Is it really not possible to create multiple constructors for a class in dart?

in my Player Class, If I have this constructor

Player(String name, int col         


        
7条回答
  •  盖世英雄少女心
    2021-02-03 17:00

    If your class uses final parameters the accepted answer will not work. This does:

    class Player {
      final String name;
      final String color;
    
      Player(this.name, this.color);
    
      Player.fromPlayer(Player another) :
        color = another.color,
        name = another.name;
    }
    

提交回复
热议问题