This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: cargandoGeneralmente | |
? Center(child: CircularProgressIndicator()) | |
: Form( | |
key: _claveFormulario, | |
child: ListView( | |
shrinkWrap: true, | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.all(16.0), | |
child: TextFormField( | |
validator: (value) { | |
if (value.isEmpty) { | |
return 'Escribe el correo electrónico'; | |
} | |
if (!value.contains("@")) { | |
return 'El correo electrónico debe llevar un @'; | |
} | |
return null; | |
}, | |
controller: _email, | |
decoration: InputDecoration( | |
hintText: 'correo@dominio', | |
labelText: "Correo electrónico"), | |
keyboardType: TextInputType.emailAddress, | |
), | |
), | |
Padding( | |
padding: EdgeInsets.all(16.0), | |
child: TextFormField( | |
controller: _password, | |
validator: (value) { | |
if (value.isEmpty) { | |
return 'Escribe la contraseña'; | |
} | |
return null; | |
}, | |
decoration: InputDecoration( | |
hintText: 'Contraseña', labelText: 'Contraseña'), | |
obscureText: true, /* <-- Aquí */ | |
), | |
), | |
Builder( | |
builder: (context) => Padding( | |
padding: EdgeInsets.all(16.0), | |
child: RaisedButton( | |
color: Colors.blue, | |
textColor: Colors.white, | |
child: cargandoBoton | |
? CircularProgressIndicator( | |
valueColor: | |
AlwaysStoppedAnimation<Color>(Colors.white), | |
) | |
: Text('Iniciar sesión'), | |
onPressed: () async { | |
if (!_claveFormulario.currentState.validate()) { | |
return; | |
} | |
if (cargandoBoton) return; | |
bool respuesta = | |
await login(_email.text, _password.text); | |
if (respuesta) { | |
navegarAEscritorio(); | |
} else { | |
Scaffold.of(context).showSnackBar( | |
SnackBar( | |
content: | |
Text('Datos incorrectos. Intenta de nuevo'), | |
duration: Duration(seconds: 1), | |
), | |
); | |
} | |
}, | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment