firebase - I/flutter (16908): [firebase_auth/invalid-email] 电子邮件地址格式错误
问题描述
你好这是我下面的代码,我想使用电子邮件和密码对firebase进行身份验证,但是当我将电子邮件和密码输入作为普通字符串时,我会选择“电子邮件地址格式错误”。错误消息和加载微调器永远转动,我卡在这个页面上,请帮助我...谢谢。---------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------
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,
),
),
),
],
),
),
),
),
);
}
}
解决方案
在您的onChanged
for your email and passwordTextField
中,
您:
将您的电子邮件值从 TextField 设置为密码
password = value;
并将您的密码值从 TextField 设置为电子邮件
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;
},
),
推荐阅读
- angular - 如何使用 RxJs 将两个 Observable 组合成一个 Observable Array
- mysql - SQL:连接两个表之间的外键并仅返回项目数;不是实际项目
- tensorflow - nvcc 错误:使用 bazel 构建 tensorflow 时,'cicc' 以状态 0xC0000005 (ACCESS_VIOLATION) 死亡
- django - Django + MongoDB - pymongo.errors.ServerSelectionTimeoutError
- session - 在 ASP.NET Core 中使用 Response.Redirect 时,临时数据/会话始终为空
- angular - 在设置值之前等待方法完成
- if-statement - 涉及 Vlookup 和 IFNA 的多个 If 条件
- docker - 将多个 .yml 文件传递给 docker-compose
- javascript - 禁用按钮后不再执行 JavaScript
- c - 我不明白的 strcmp 的编译器优化,针对常量字符串