Fiz a implementação como mostrado na aula, entretanto o formulário não fechou. Podem me ajudar?
[EDIT] Eu não havia colocado 'Navigator.pop(context);' dentro do 'Confirmar' do AlertDialog, por isso o formulário não fechava.
[imports]
class TransferenciaForm extends StatefulWidget {
final Contato contato;
TransferenciaForm(this.contato);
@override
_TransferenciaFormState createState() => _TransferenciaFormState();
}
class _TransferenciaFormState extends State<TransferenciaForm> {
final TextEditingController _valueController = TextEditingController();
final TransferenciaWebClient _webClient = TransferenciaWebClient();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Nova transferência'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.contato.nome,
style: TextStyle(
fontSize: 24.0,
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Text(
widget.contato.conta.toString(),
style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.bold,
),
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: TextField(
controller: _valueController,
style: TextStyle(fontSize: 24.0),
decoration: InputDecoration(labelText: 'Valor'),
keyboardType: TextInputType.numberWithOptions(decimal: true),
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: SizedBox(
width: double.maxFinite,
child: RaisedButton(
child: Text('Transferir'),
onPressed: () {
final double valor =
double.tryParse(_valueController.text);
final transferenciaCriada =
Transferencia(valor, widget.contato);
showDialog(
context: context,
builder: (contextDialog) {
return TransferenciaAuthDialog(
onConfirm: (String password) {
_save(transferenciaCriada, password, context);
},
);
},
);
},
),
),
)
],
),
),
),
);
}
void _save(Transferencia transferenciaCriada, String password,
BuildContext context) async {
_webClient
.save(transferenciaCriada, password)
.then((transferenciaRecebida) {
if (transferenciaRecebida != null) {
Navigator.pop(context);
}
});
}
}
import 'package:flutter/material.dart';
class TransferenciaAuthDialog extends StatefulWidget {
final Function(String) onConfirm;
TransferenciaAuthDialog({
@required this.onConfirm,
});
@override
_TransferenciaAuthDialogState createState() =>
_TransferenciaAuthDialogState();
}
class _TransferenciaAuthDialogState extends State<TransferenciaAuthDialog> {
final TextEditingController _passwordController = TextEditingController();
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text("Autenticação"),
content: TextField(
controller: _passwordController,
obscureText: true,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 64,
letterSpacing: 24,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
),
maxLength: 4,
keyboardType: TextInputType.number,
),
actions: [
FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("CANCEL"),
),
FlatButton(
onPressed: () {
widget.onConfirm(_passwordController.text);
#
# O erro foi não ter colocado o .pop abaixo
# Navigator.pop(context);
#
},
child: Text("CONFIRM"),
),
],
);
}
}