Я хотел бы знать, как я могу взять исключения firebase и показать их в alertDialog во Flutter. Спасибо!
Это метод входа в мой auth_service, я знаю, что cath (e) выводит ошибки в консоли, но я хотел бы знать, есть ли способ отредактировать эти ошибки и показать их в alertDialog
это метод внутри класса моего файла auth_servi c .dart
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();
},
),
);
},
),
],
),
),
],
),
),
),
),
);
} }