【问题标题】:ArgumentError (Invalid argument(s) (onError): The error handler of Future.catchError must return a value of the future's type)ArgumentError(无效参数(onError):Future.catchError 的错误处理程序必须返回未来类型的值)
【发布时间】:2023-02-16 03:56:19
【问题描述】:

ArgumentError(无效参数(onError):Future.catchError 的错误处理程序必须返回未来类型的值)

final User? firebaseUser = (
        await fAuth.signInWithEmailAndPassword(
            email: emailTextEditingController.text.trim(),
            password: passwordTextEditingController.text.trim()
        ).catchError((msg) {
            Navigator.pop(context);
            Fluttertoast.showToast(msg: "Error" +msg.toString());
        })).user;

       
  

【问题讨论】:

  • 你能重新格式化你的代码吗

标签: flutter


【解决方案1】:

创建异步方法来获取用户。

User? firebaseUser() async {
  return await fAuth
      .signInWithEmailAndPassword(
          email: emailTextEditingController.text.trim(),
          password: passwordTextEditingController.text.trim())
      .user;
}

您可以显示基于空用户的吐司。

checkError() async {
  final user = await firebaseUser();

  if(user==null){
    //show message
  }
}

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2021-10-29
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多