问题描述
飞镖类中的超级关键字和关键词做什么?
下面的代码是一个示例:
what does the super and key words do in a dart class?one example is the code below:
class CardTitle extends StatelessWidget {
final String title;
const CardTitle(this.title, **{Key key}**) : **super(key: key)**;
推荐答案
super
用于调用基类的构造函数。因此,在您的示例中, CardTitle
的构造函数正在调用 StatelessWidget
的构造函数。
super
is used to call the constructor of the base class. So in your example, the constructor of CardTitle
is calling the constructor of StatelessWidget
.
Key
是Flutter中使用的一种类型,用于标识小部件,并允许Flutter知道何时在树中移动的小部件与该小部件相同。以前在其他位置。这里有一个有关按键的很好的视频:
Key
is a type used in Flutter to identify widgets and allows Flutter to know when a widget that's moved in the tree is the same as a widget that was previously in a different location. There's a good video about keys here: https://www.youtube.com/watch?v=kn0EOS-ZiIc
这篇关于super和Key在颤振中起什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!