【问题标题】:Flutter - Firebase The email is badly formatted, nullFlutter - Firebase 电子邮件格式错误,为空
【发布时间】:2020-04-15 21:57:42
【问题描述】:

在我的应用程序中输入电子邮件时收到此错误。 我一直在输入 hamtaco123@gmail.com 之类的内容,并且必须至少有 6 个字符长

.. .. ..

class _RegistrationScreenState extends State<RegistrationScreen> {
  final _auth = FirebaseAuth.instance;
  String email;
  String password;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: 24.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Hero(
              tag: 'logo',
              child: Container(
                height: 200.0,
                child: Image.asset('images/logo.png'),
              ),
            ),
            SizedBox(
              height: 48.0,
            ),
            TextField(
              textAlign: TextAlign.center,
              keyboardType: TextInputType.emailAddress,
              onChanged: (value) {
                email = value;
              },
              decoration:
                  kTextFieldDecoration.copyWith(hintText: 'Enter your Email'),
            ),
            SizedBox(
              height: 8.0,
            ),
            TextField(
              textAlign: TextAlign.center,
              obscureText: true,
              onChanged: (value) {
                password = value;
              },
              decoration: kTextFieldDecoration.copyWith(
                  hintText: 'Enter your Password'),
            ),
            SizedBox(
              height: 24.0,
            ),
            RoundedButton(
                text: 'Register',
                color: Colors.blueAccent,
                onPressed: () async {
                  try {
                    final FirebaseUser newUser =
                        (await _auth.createUserWithEmailAndPassword(
                      email: email,
                      password: password,
                    ))
                            .user;
                    if (newUser != null) {
                      Navigator.pushNamed(context, ChatScreen.id);
                    }
                  } catch (e) {
                    print(e);
                  }
                }),
          ],
        ),
      ),
    );
  }
}

--------------

--------------

--------------


--------------

--------------

--------------


【问题讨论】:

    标签: flutter dart firebase-authentication


    【解决方案1】:

    在您的代码中,只需进行如下更改即可删除多余的空格,

    try {
                        final FirebaseUser newUser =
                            (await _auth.createUserWithEmailAndPassword(
                          email: email.trim(),
                          password: password.trim(),
                        ))
                                .user;
                        if (newUser != null) {
                          Navigator.pushNamed(context, ChatScreen.id);
                        }
                      } catch (e) {
                        print(e);
                      }
    

    修剪您的电子邮件和密码字段,例如 email.trim()password.trim()

    【讨论】:

    • 谢谢你的工作。你能解释一下这背后的原因吗,我打印了电子邮件,那里没有我能看到的空格。
    猜你喜欢
    • 2019-06-27
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 2018-09-24
    • 2021-01-03
    • 2020-02-27
    • 1970-01-01
    相关资源
    最近更新 更多