Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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
You can’t perform that action at this time.