Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 9, 2020 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/2653d806a878aa234ca7e2b4fd6ac651 to your computer and use it in GitHub Desktop.
Save parzibyte/2653d806a878aa234ca7e2b4fd6ac651 to your computer and use it in GitHub Desktop.
@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