gpt4 book ai didi

syntax - Dart方法签名中的大括号有什么用

转载 作者:行者123 更新时间:2023-12-04 01:03:38 24 4
gpt4 key购买 nike

class TapboxA extends StatefulWidget {

TapboxA({Key key}) : super(key: key);

}

这部分 :
TapboxA({Key key}) 

下半场
super(key: key);

我明白,(对父类(super class)构造函数的调用)。

但是什么是
{Key key}

语法在做什么?

最佳答案

在 Dart 构造函数(和其他方法)中可以有可选的命名参数:

MyClass({String namedParam}){//...}

对于 Flutter 小部件构造函数:
TapboxA({Key key})  // TapboxA constructor defines a named parameters `key`
: super(key: key); //which is used within the super constructor call (which also has `key` as named parameter )

您可以找到有关 optional named parameters in the Dart language tour 的更多信息

关于syntax - Dart方法签名中的大括号有什么用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46717971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com