如何在AlertDialo中显示firebase例外(错误)
我想知道如何处理firebase异常,并在Flatter中的alertDialog中显示它们。 谢谢大家! 这是登录我的auth_服务的方法,我知道cath(e)会在控制台中打印错误,但我想知道是否有任何方法可以编辑这些错误并在alertDialog中显示它们 这是auth_servic.dart文件类中的方法如何在AlertDialo中显示firebase例外(错误),firebase,flutter,android-alertdialog,Firebase,Flutter,Android Alertdialog,我想知道如何处理firebase异常,并在Flatter中的alertDialog中显示它们。 谢谢大家! 这是登录我的auth_服务的方法,我知道cath(e)会在控制台中打印错误,但我想知道是否有任何方法可以编辑这些错误并在alertDialog中显示它们 这是auth_servic.dart文件类中的方法 static void login(String email, String password) async { try { await _auth.signInW
static void login(String email, String password) async {
try {
await _auth.signInWithEmailAndPassword(email: email, password: password);
} catch (e) {
print(e);
}
}
myLoginPage:
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:jobly10/screens/google_signup.dart'; import 'package:jobly10/screens/passwordRecover.dart'; import 'package:jobly10/services/auth_service.dart'; import 'package:page_transition/page_transition.dart'; import '../checkifsignedupornot.dart'; import 'google_signup.dart'; import 'package:modal_progress_hud/modal_progress_hud.dart';
bool showSpinner = false;
class Login extends StatefulWidget { static final String id = 'login_screen'; @override _LoginState createState() =>
_LoginState(); }
class _LoginState extends State<Login> { bool showSpinner = false; final _formKey = GlobalKey<FormState>(); String _email, _password;
_submit() {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
// Logging in the user w/ Firebase
AuthService.login(_email, _password);
} }
@override Widget build(BuildContext context) {
return Scaffold(
body: ModalProgressHUD(
inAsyncCall: showSpinner,
child: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Form(
key: _formKey,
child: Column(
children: <Widget>[
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Container(
child: Center(
child: Text(
'Jobly',
style: TextStyle(
color: Colors.redAccent,
fontSize: 50,
fontFamily: 'Pacifico-Regular',
shadows: <Shadow>[
Shadow(
offset: Offset(2.0, 3.0),
blurRadius: 1.0,
color: Colors.black),
]),
),
),
),
),
],
),
),
SizedBox(
height: 10,
),
Container(
height: 50,
width: 320,
child: Center(
child: Text(
'No pierdas la opertunidad. Sigue active y actualizado',
style: TextStyle(
color: Colors.black26,
fontFamily: 'VarelaRound-Regular',
fontSize: 12.0),
),
),
),
Container(
height: 50,
width: 320,
child: TextFormField(
keyboardType: TextInputType.emailAddress,
cursorColor: Colors.black,
style: TextStyle(
fontFamily: 'Poppins-Medium',
fontSize: 15.0,
color: Colors.black),
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(8.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
labelText: 'Correo',
),
validator: (input) => input.trim().isEmpty
? 'Ingrese un correo valido'
: null,
onSaved: (input) => _email = input,
),
),
SizedBox(height: 10.0),
Container(
height: 50,
width: 320,
child: TextFormField(
obscureText: true,
cursorColor: Colors.black,
style: TextStyle(
fontFamily: 'Poppins-Medium',
fontSize: 15.0,
color: Colors.black),
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(8.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
),
labelText: 'Contraseña',
),
validator: (input) => input.trim().isEmpty
? 'Ingrese una contraseña valida'
: null,
onSaved: (input) => _password = input,
),
),
SizedBox(height: 10.0),
Container(
height: 50,
width: 320,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Colors.black87,
Colors.black87,
]),
borderRadius: BorderRadius.circular(6.0),
),
margin: EdgeInsets.symmetric(
vertical: 0.0, horizontal: 0.0),
child: Material(
color: Colors.transparent,
child: InkWell(
highlightColor: Colors.deepOrange,
splashColor: Colors.black87,
onTap: () {
setState(() {
showSpinner = true;
});
_submit();
},
child: Center(
child: Text(
"Ingresar",
style: TextStyle(
color: Colors.white,
backgroundColor: null,
fontFamily: "CM Sans Serif",
fontSize: 12,
letterSpacing: 1.0),
),
),
),
),
),
SizedBox(height: 20.0),
Container(
height: 15,
width: 320,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
height: 1,
color: Colors.black26,
),
),
SizedBox(
width: 10.0,
),
Center(
child: Text(
'or',
style: TextStyle(
color: Colors.black26, fontSize: 13.0),
),
),
SizedBox(
width: 10.0,
),
Expanded(
child: Container(
height: 1,
color: Colors.black26,
),
),
],
),
),
SizedBox(height: 15.0),
InkWell(
child: Text(
"Registrase.",
style: TextStyle(
color: Colors.black,
fontFamily: "CM Sans Serif",
fontSize: 13,
letterSpacing: 1.0),
),
onTap: () {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.upToDown,
child:
CheckingSignup(), //will pass the route to the CheckIfSignedupOrNot Class
duration: Duration(milliseconds: 200),
),
);
},
),
InkWell(
child: Text(
"Perdi mi contraseña.",
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return PasswordRecover();
},
),
);
},
),
InkWell(
child: Text(
"Google Sign In",
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return GoogleSigninSignUp();
},
),
);
},
),
InkWell(
child: Text(
"Ingresar con numero de telefono",
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return CheckingPhoneLogin();
},
),
);
},
),
],
),
),
],
),
),
),
),
);
} }
import'包装:flift/cupertino.dart';进口“包装:颤振/材料.省道”;导入“包:jobly10/screens/google_signup.dart”;导入“package:jobly10/screens/passwordRecover.dart”;导入“包:jobly10/services/auth_service.dart”;导入“package:page_transition/page_transition.dart”;导入“../checkifsignedupornot.dart”;导入“google_signup.dart”;导入“程序包:modal_progress_hud/modal_progress_hud.dart”;
bool showSpinner=false;
类Login扩展StatefulWidget{static final String id='Login_screen';@override_LoginState createState()=>
_LoginState();}
类_LoginState扩展状态{bool showSpinner=false;final _formKey=GlobalKey();字符串_email,_password;
_提交(){
if(_formKey.currentState.validate()){
_formKey.currentState.save();
//登录用户w/Firebase
AuthService.login(_电子邮件,_密码);
} }
@覆盖小部件构建(构建上下文){
返回脚手架(
正文:ModalProgressHUD(
inAsyncCall:showSpinner,
儿童:中心(
子:容器(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
形式(
键:_formKey,
子:列(
儿童:[
容器(
孩子:排(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
居中(
子:容器(
儿童:中心(
子:文本(
“Jobly”,
样式:TextStyle(
颜色:Colors.redAccent,
尺寸:50,
fontFamily:“Pacifico Regular”,
阴影:[
影子(
偏移量:偏移量(2.0,3.0),
半径:1.0,
颜色:颜色。黑色),
]),
),
),
),
),
],
),
),
大小盒子(
身高:10,
),
容器(
身高:50,
宽度:320,
儿童:中心(
子:文本(
“没有歌剧院,我是积极的现实主义者”,
样式:TextStyle(
颜色:颜色。黑色,
fontFamily:“VarelaRound常规”,
字体大小:12.0),
),
),
),
容器(
身高:50,
宽度:320,
子项:TextFormField(
键盘类型:TextInputType.emailAddress,
光标颜色:颜色。黑色,
样式:TextStyle(
fontFamily:‘罂粟花中等’,
字体大小:15.0,
颜色:颜色。黑色),
装饰:输入装饰(
contentPadding:const EdgeInsets.all(8.0),
边框:大纲输入边框(
边界半径:边界半径。圆形(5.0),
),
标签文字:“科雷奥”,
),
验证器:(输入)=>input.trim().isEmpty
“安格尔·瓦利多”
:null,
onSaved:(输入)=>\u电子邮件=输入,
),
),
尺寸箱(高度:10.0),
容器(
身高:50,
宽度:320,
子项:TextFormField(
蒙昧文字:对,
光标颜色:颜色。黑色,
样式:TextStyle(
fontFamily:‘罂粟花中等’,
字体大小:15.0,
颜色:颜色。黑色),
装饰:输入装饰(
contentPadding:const EdgeInsets.all(8.0),
边框:大纲输入边框(
边界半径:边界半径。圆形(5.0),
),
labelText:“Contraseña”,
),
验证器:(输入)=>input.trim().isEmpty
“安格尔·尤娜·瓦利达”
:null,
onSaved:(输入)=>\u密码=输入,
),
),
尺寸箱(高度:10.0),
void error(String error, BuildContext context,
{Color backgroundColor = Colors.white,
TextAlign textAlign = TextAlign.start,
double fontSize = 20,
FontWeight fontWeight = FontWeight.bold,
Color textColor = Colors.red}) {
AlertDialog errorAlertDialog = new AlertDialog(
elevation: 0,
backgroundColor: backgroundColor,
content: SelectableText(
error,
textAlign: textAlign,
style: TextStyle(
color: textColor, fontSize: fontSize, fontWeight: fontWeight),
));
showDialog(context: context, child: errorAlertDialog);
}