Mrudul Addipalli
Mrudul Addipalli

Reputation: 624

how does below constructor work in dart, I have extracted widget and flutter has given the below constructor for my widget

ExtractedWidgetForLst({
Key key,
@required List<Expense> expensesData,
}) : _expensesData = expensesData, super(key: key);

If we need any argument to be passed to the class, we use parameterized constructor and in that we use super() to call parent constructor inside the body if needed. and if we don't need calling super then just we use this keyword in the parameter itself, e.g:

class MyClass{
  String name;
  String surname;
  MyClass({this.name,this.surname});
}

but what does operator ' : ' and super means over this scenario.

Upvotes: 2

Views: 64

Answers (1)

Aaron Ayalew
Aaron Ayalew

Reputation: 123

: is for the parameter and super(key: key); calls the Constructor from the inherited Widget class

Upvotes: 2

Related Questions