Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

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.

question from:https://stackoverflow.com/questions/65644964/how-does-below-constructor-work-in-dart-i-have-extracted-widget-and-flutter-has

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...