gpt4 book ai didi

flutter - 我听不懂这条线

转载 作者:行者123 更新时间:2023-12-03 03:34:57 25 4
gpt4 key购买 nike

class SharedPreferencesDemo extends StatefulWidget {
SharedPreferencesDemo({Key key}) : super(key: key); <-------- This line

@override
SharedPreferencesDemoState createState() => SharedPreferencesDemoState();
}

我可以理解结肠前后的部分,但是中间的结肠是什么意思呢?我说的是结肠位于这两个部分之间。这条线最终意味着什么?

最佳答案

这称为构造函数。用于通过调用new SharedPreferencesDemo()或仅SharedPreferencesDemo()来创建类的新实例。

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

这是每个部分的说明。
SharedPreferencesDemo - constructor name
(...) - constructor arguments
{Key key} - optional named arguments
: - initializer list, used to call super or initialize variables including final ones
super - calls parent constructor (StatefulWidget.StatefulWidget)
key: key - sets value of optional argument [key] for parent constructor

初始化程序列表用于初始化最终变量或使用指定的参数调用构造函数。这是另一个例子:

class AuthClient {
AuthClient({ String username, String password }) :
_token = '$username:$password';

final String _token;
}

关于flutter - 我听不懂这条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61702815/

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