You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter位置参数报错:AuthStateLoggedOut需1个位置参数却传入0个

问题解决:‘AuthStateLoggedOut.new’需要1个位置参数,但找到0个

问题原因

你的AuthStateLoggedOut类构造函数定义了一个必填的位置参数Exception? e,但你在调用时只传递了exception和isLoading这两个命名参数,完全没有提供这个位置参数,因此触发了参数缺失的错误。而且这个位置参数e在构造函数里没有被使用,属于冗余定义。

修复方案(推荐)

直接删除构造函数里冗余的位置参数,只保留命名参数,这样原有调用代码无需修改即可正常运行:

修改后的AuthStateLoggedOut类代码:

class AuthStateLoggedOut extends AuthState with EquatableMixin{
  final Exception? exception;
  final bool isLoading;
  // 移除多余的位置参数e
  const AuthStateLoggedOut({required this.exception, required this.isLoading});
  
  @override
  List<Object?> get props => [exception, isLoading];
}

备选方案(不推荐)

如果一定要保留位置参数,调用时必须先传递该位置参数,再传命名参数(但此方案无实际意义,因为位置参数未被使用):

修改后的调用代码:

emit(const AuthStateLoggedOut(null, exception: null, isLoading:false));

内容的提问来源于stack exchange,提问作者user22977892

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 06:19:57