Dart Multiple Constructors

后端 未结 7 1791
一向
一向 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:03

    If you already used a constructor with params in the project and now you figured out that you need some no params default constructor you can add an empty constructor.

    class User{
    String name;
    
       User({this.name}); //This you already had before
       User.empty(); //Add this later 
    }
    

提交回复
热议问题