简体   繁体   English

未处理的异常:NoSuchMethodError:在 null 上调用了 getter 'isEmailVerified'

[英]Unhandled Exception: NoSuchMethodError: The getter 'isEmailVerified' was called on null

I am getting the above mentioned error when logging in. This exception is raised even after I am ensuring that the isEmailVerified() is called only after checking whether the current user is null or not.登录时出现上述错误。即使在确保仅在检查当前用户是否为 null 后才调用isEmailVerified()后,也会引发此异常。

My authentication.dart file looks like below:我的authentication.dart文件如下所示:

import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';

abstract class BaseAuth {
  Future<String> signIn(String email, String password);

  Future<String> signUp(String email, String password);

  Future<FirebaseUser> getCurrentUser();

  Future<void> sendEmailVerification();

  Future<void> signOut();

  Future<bool> isEmailVerified();
}
class Auth implements BaseAuth {
  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

  Future<String> signIn(String email, String password) async {
    AuthResult result = await _firebaseAuth.signInWithEmailAndPassword(
        email: email, password: password);
    FirebaseUser user = result.user;
    return user.uid;
  }

  Future<String> signUp(String email, String password) async {
    AuthResult result = await _firebaseAuth.createUserWithEmailAndPassword(
        email: email, password: password);
    FirebaseUser user = result.user;
    sendEmailVerification();
    return user.uid;
  }

  Future<FirebaseUser> getCurrentUser() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user;
  }

  Future<void> signOut() async {
    return _firebaseAuth.signOut();
  }

  Future<void> sendEmailVerification() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    user.sendEmailVerification();
  }

  Future<bool> isEmailVerified() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user.isEmailVerified;
  }
}

And inside the LoginPage , I am checking like this:LoginPage里面,我是这样检查的:

if(auth.signIn(email, password)!=null)
      {
        if(auth.getCurrentUser()!=null)
          {
            if(auth.isEmailVerified() != null) {
              Toast.show("Login Successful!", context, duration: Toast.LENGTH_SHORT, gravity:  Toast.BOTTOM);
              Route route = MaterialPageRoute(builder: (context) => HomePage());
              Navigator.pushReplacement(context, route);
            }
          }
      }

I don't know how to resolve this.我不知道如何解决这个问题。 Any help is appreciated.任何帮助表示赞赏。

From your Auth class, your methods have future signatures.从您的Auth class 中,您的方法具有未来的签名。
You will have to await their results since it will be needed by the other conditions.您将不得不await他们的结果,因为其他条件将需要它。

You can do:你可以做:

if((await auth.signIn(email, password))!=null){
      if((await auth.getCurrentUser())!=null){
        if((await auth.isEmailVerified()) != null) {
          Toast.show("Login Successful!", context, duration: Toast.LENGTH_SHORT, gravity:  Toast.BOTTOM);
          Route route = MaterialPageRoute(builder: (context) => HomePage());
          Navigator.pushReplacement(context, route);
        }
      }
    }

But the snippet above must be placed in within an async method.但是上面的代码片段必须放在async方法中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的异常:NoSuchMethodError:在 null 上调用了 getter &#39;uid&#39; - Unhandled Exception: NoSuchMethodError: The getter 'uid' was called on null Firebase/Flutter:未处理的异常:NoSuchMethodError:在 null 上调用了 getter 'isNotEmpty' - Firebase/Flutter : Unhandled Exception: NoSuchMethodError: The getter 'isNotEmpty' was called on null 颤振未处理的异常:NoSuchMethodError:方法&#39;then&#39;在null上被调用 - Flutter Unhandled Exception: NoSuchMethodError: The method 'then' was called on null 未处理的异常:NoSuchMethodError:在 null 上调用了方法“findAncestorStateOfType” - Unhandled Exception: NoSuchMethodError: The method 'findAncestorStateOfType' was called on null 未处理的异常:NoSuchMethodError:在 null 上调用了方法“addUser” - Unhandled Exception: NoSuchMethodError: The method 'addUser' was called on null 未处理的异常:NoSuchMethodError:在null上调用了方法&#39;split&#39; - Unhandled Exception: NoSuchMethodError: The method 'split' was called on null 未处理的异常:NoSuchMethodError:在 null 上调用了方法“addAdvogado”。 关于颤振 - Unhandled Exception: NoSuchMethodError: The method 'addAdvogado' was called on null. On Flutter 获取数据错误:未处理的异常:NoSuchMethodError:在 null 上调用了方法“[]” - fetcing data error :Unhandled Exception: NoSuchMethodError: The method '[]' was called on null 未处理的异常:NoSuchMethodError:在 null 上调用了方法“[]”。 访问firestore时 - Unhandled Exception: NoSuchMethodError: The method '[]' was called on null. when accessing firestore 如何解决这个问题 [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:NoSuchMethodError:getter &#39;phone&#39; 在 null 上被调用。 错误? - How to fix this [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: NoSuchMethodError: The getter 'phone' was called on null. error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM