Dart Multiple Constructors

后端 未结 7 1663
一向
一向 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:24

    As @Günter Zöchbauer already said

    You can only have one unnamed constructor, but you can have any number of additional named constructors in Flutter.

    • By using named constructor you can create multiple constructors in the same class.
    • Each constructor will have a unique name. So that you can identify each of them.

    Syntax for named constructor :

    class_name.constructor_name (arguments) { 
       // If there is a block of code, use this syntax
    
       // Statements
    }
    
    or
    
    class_name.constructor_name (arguments); 
       // If there is no block of code, use this syntax
    

    For more insights Click Here

    To know about various types of constructors in Flutter Click Here

    0 讨论(0)
提交回复
热议问题