gpt4 book ai didi

Flutter 如何将变量设为私有(private)并在构造函数中使用 @required 对其进行初始化

转载 作者:行者123 更新时间:2023-12-03 02:56:16 26 4
gpt4 key购买 nike

如何将字段设为私有(private)并使用 @required 对其进行注释在类里面?

例如,这段代码给了我错误:

class AuthenticationService {
final Api _api;

AuthenticationService({@required this._api}); // error in this line
}

最佳答案

class AuthenticationService {
final Api _api;

AuthenticationService({@required Api api}) : _api = api;
}

关于Flutter 如何将变量设为私有(private)并在构造函数中使用 @required 对其进行初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57936662/

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