简体   繁体   中英

Flutter Firebaseauth exception Error “Email is badly formatted”

错误图片

Please I need help on this. Followed a tutorial whereby everything looks good, but whenever i try to signup, my app freeze and throw-up this error.

Its especially on the signup method

I need help on this to move forward.

enum Status { Uninitialized, Authenticated, Authenticating, Unauthenticated }

class UserProvider with ChangeNotifier {
  FirebaseAuth _auth;
  User _user;
  Status _status = Status.Uninitialized;
  Status get status => _status;
  User get user => _user;
  UserServices _userServices = UserServices();

  UserProvider.initialize() : _auth = FirebaseAuth.instance {
    _auth.authStateChanges().listen(_onStateChanged);
  }

  Future<bool> signUp(
      String name, String phone, String email, String password) async {
    try {
      _status = Status.Authenticating;
      notifyListeners();
      await _auth
          .createUserWithEmailAndPassword(
              email: email.trim(), password: password)
          .then((user) {
        Map<String, dynamic> values = {
          "name": name,
          "email": email,
          "userId": user.user.uid
        };
        _userServices.createUser(values);
      });
      return true;
    } catch (e) {
      _status = Status.Unauthenticated;
      notifyListeners();
      print(e.toString());
      return false;
    }
  }

  Future<void> _onStateChanged(User event) async {
    if (user == null) {
      _status = Status.Unauthenticated;
    } else {
      _user = user;
      _status = Status.Authenticated;
    }
    notifyListeners();
  }
}

"Email is badly formatted" appears because of email input does not include @gmail.com for example. Maybe you can provide some of your code for more details.

just Print the emailid and emailid.trim() check whether it is correct or not

I fixed it, the problem was the order of the String elements (email, name, phone, password), the order on the register page must be the same with the order on the Provider page.

That's why it's taking phone number for an email, which always spring up that error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM