断言失败:'email!= null'?

时间:2020-09-15 08:24:27

标签: database flutter null

有人知道为什么我的结果为空吗?当我想注册调试控制台时,显示:断言失败:行183位置12:'email!= null':不正确。它显示为空。当我按下“注册”按钮时,这是我的注册代码,而其他代码则是我的身份验证类。如果有人知道,请发表评论。

 Future <void> signUp() async {

     if(_formKey.currentState.validate()){
       setState(() {

         isLoading = true;
       });

       await authService.signUpWithEmailAndPassword(_email,
           _password).then((result)  {
         if(result != null){

           Map<String,String> userDataMap = {
             "Username" : _Username,
             "Email" : _email,
             "Nation" : _Nation,
           };

           databaseService.addUserInfo(userDataMap);

           HelperFunction.saveUserLoggedInSharedPreference(true);
           HelperFunction.saveUserNameSharedPreference(_Username);
           HelperFunction.saveUserEmailSharedPreference(_email);
           HelperFunction.saveUserNationSharedPreference(_Nation);

           Navigator.pushReplacement(context, MaterialPageRoute(
               builder: (context) => LoadingBarForUserCreation()
           ));
         }else{
           print(result);
         }
       }).catchError((e){
         _showSettingPanelForEmail();
       });
     }

AuthService

class AuthService{

  final FirebaseAuth _auth = FirebaseAuth.instance;

  Userf _userFromFirebaseUser(User user){

    return user != null ? Userf(uid: user.uid) : null;
  }

  Stream<Userf> get user {
    return _auth.onAuthStateChanged
        .map(_userFromFirebaseUser);
  }


  Future signInWithEmailAndPassword(String email, String password) async {
    try {
      User user = (await _auth.signInWithEmailAndPassword(
          email: email, password: password)).user;
      return _userFromFirebaseUser(user);
    } catch (e) {
      print(e.toString());
      return null;
    }
  }

  Future signUpWithEmailAndPassword(String email, String password) async {
    try {
      User user = (await _auth.createUserWithEmailAndPassword(
          email: email, password: password)).user;
      return _userFromFirebaseUser(user);
    } catch (e) {
      print(e.toString());
      return null;
    }
  }





  Future signOut() async {
    try {
      return await _auth.signOut();
    } catch (e) {
      print(e.toString());
      return null;
    }
  }



}

0 个答案:

没有答案