this.在构造函数中使用参数初始化成员的语法方式仅在普通构造函数中有效,而在
factory构造函数中则无效。(
factory构造函数没有
this对象!)
相反,您将需要手动将
factory构造函数的参数转发给实际的构造函数。例如:
class User { static User _singleton; final String email; final String token; final bool wordtestCompleted; User._internal({this.email, this.token, this.wordtestCompleted}); factory User({String email, String token, bool wordtestCompleted}) { return _singleton ??= User._internal( email: email, token: token, wordtestCompleted: wordtestCompleted, ); }}


