簡體   English   中英

Flutter - Firebase 電子郵件格式錯誤,為空

[英]Flutter - Firebase The email is badly formatted, null

在我的應用程序中輸入電子郵件時出現此錯誤。 我一直在輸入 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);
                  }
                }),
          ],
        ),
      ),
    );
  }
}

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

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

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


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

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

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


在您的代碼中,只需按如下方式進行更改即可刪除多余的空格,

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM