[英]Firebase Authentication "auth/invalid-email" and "The email address is badly formatted."
[英]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 和密碼TextField
的onChanged
中,
你:
將 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.