有没有办法设置构造函数可选参数? 我的意思是这样的:
User.fromData(this._name,
this._email,
this._token,
this._refreshToken,
this._createdAt,
this._expiresAt,
this._isValid,
{this.id});
它表明
命名选项参数不能以下划线开头.
但我需要这块地作为私有场地,所以,我现在迷路了.
有没有办法设置构造函数可选参数? 我的意思是这样的:
User.fromData(this._name,
this._email,
this._token,
this._refreshToken,
this._createdAt,
this._expiresAt,
this._isValid,
{this.id});
它表明
命名选项参数不能以下划线开头.
但我需要这块地作为私有场地,所以,我现在迷路了.
您需要使用一个简单的参数并初始化初始值设定项列表中的私有字段.
class User {
final String _id;
final String _name;
User.fromData(this._name, {required String id})
: _id = id;
}