繁体   English   中英

I/flutter (16908): [firebase_auth/invalid-email] email 地址格式错误

[英]I/flutter (16908): [firebase_auth/invalid-email] The email address is badly formatted

你好 下面是我的代码,我想使用电子邮件和密码对 firebase 进行身份验证,但是当我将 email 和密码输入作为普通字符串输入时,我将“email 地址格式错误”。 错误消息和加载微调器永远转动,我卡在这个页面上,请帮助我...谢谢。---------------------------- ---------------------------------------------- ---------------------------------------------- ---------------------------------------------- ---------------------------------------------- ---------------------------------------------- ---------------------------------------------- ----------

import 'package:flutter/cupertino.dart';
import 'package:naber/constants.dart';
import 'package:naber/screens/chat_screen.dart';
import 'package:flutter/material.dart';
import 'package:modal_progress_hud/modal_progress_hud.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:naber/screens/welcome_screen.dart';

class RegistrationScreen extends StatefulWidget {
  static String id="registration_screen";
  @override
  _RegistrationScreenState createState() => _RegistrationScreenState();
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ModalProgressHUD(
        inAsyncCall: showSpinner,
        child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage(kWelcomeScreenBackgroundImage),
            fit: BoxFit.cover,
          ),
        ),
          child: Padding(
            padding: EdgeInsets.all(20.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Expanded(
                  child: Padding(
                    padding: EdgeInsets.all(20.0),
                    child: Hero(
                      tag: "logo",
                      child: Container(
                        decoration: BoxDecoration(
                          image: DecorationImage(
                            image: AssetImage(kLogoImage),
                          )
                        ),
                      ),
                    ),
                  ),
                ),
                SizedBox(height: 10),
                Container(
                  decoration: BoxDecoration(
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.withOpacity(0.5),
                        spreadRadius: 5,
                        blurRadius: 7,
                        offset: Offset(0, 3), // changes position of shadow
                      ),
                    ],
                    borderRadius: BorderRadius.circular(90.0),
                    color: Colors.white,
                  ),
                  child: TextField(
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 20,
                    ),
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: "Enter your email",
                      hintStyle: kHintTextStyle,
                    ),
                    onChanged: (value){
                    password=value;
                    },
                  ),
                ),
                SizedBox(height: 15),
                Container(
                  decoration: BoxDecoration(
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.withOpacity(0.5),
                        spreadRadius: 5,
                        blurRadius: 7,
                        offset: Offset(0, 3), // changes position of shadow
                      ),
                    ],
                    borderRadius: BorderRadius.circular(90.0),
                    color: Colors.white,
                  ),
                  child: TextField(
                    obscureText: true,
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 20,
                    ),
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: "Enter your password",
                      hintStyle: kHintTextStyle,
                    ),
                    onChanged: (value) {
                      email = value;
                  }
                )
              ),
                SizedBox(height: 15),
                Container(
                  decoration: BoxDecoration(
                    boxShadow: [
                      BoxShadow(
                      color: Colors.grey.withOpacity(0.5),
                      spreadRadius: 5,
                      blurRadius: 7,
                      offset: Offset(0, 3), // changes position of shadow
                    ),
                  ],
                    gradient: LinearGradient(
                      colors: [
                        kNaberTextColor1,
                        kNaberTextColor1,
                        ],
                      ),
                    borderRadius: BorderRadius.circular(90.0),
                      ),
                      child: FlatButton(
                        onPressed: ()async{
                          setState(() {
                            showSpinner=true;
                          });
                         try{
                           final newUser = await _auth.createUserWithEmailAndPassword(
                               email: email, password: password);
                           if(newUser!=null){
                             setState(() {
                               showSpinner=false;
                             });
                             Navigator.pushNamed(context, WelcomeScreen.id);
                           }
                         }
                         catch(e){
                           print(e);
                         }
                        },
                        child: Text(
                          "Kayıt Ol",
                          style: kButtonTextStyle,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

在您的 email 和密码TextFieldonChanged中,
你:
将 TextField 中的 email 值设置为密码

password = value;

并将您的密码值从 TextField 设置为 email

email = value;

就换吧像这样:

TextField(
          textAlign: TextAlign.center,
          style: TextStyle(
            color: Colors.black,
            fontSize: 20,
          ),
          decoration: InputDecoration(
            border: InputBorder.none,
            hintText: "Enter your email",
            hintStyle: kHintTextStyle,
          ),
          onChanged: (value) {
            email = value;
          },
        ),
 TextField(
          textAlign: TextAlign.center,
          style: TextStyle(
            color: Colors.black,
            fontSize: 20,
          ),
          decoration: InputDecoration(
            border: InputBorder.none,
            hintText: "Enter your password",
            hintStyle: kHintTextStyle,
          ),
          onChanged: (value) {
            password = value;
          },
        ),

暂无
暂无

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

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