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

Viewed 37
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.

1 Answers

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

Related