Problem when returning from a Custonalertdialog - Flutter

Asked

Viewed 278 times

0

I have a Custonalertdialog that saves information in the bank, for this, by clicking the SEND button I use a await. The information is saved in the database successfully, but the application hangs and does not execute the command to close Alert "Navigator.pop".

class ConfirmarPresencaWidget extends StatelessWidget {
  final ValueChanged<bool> parentAction;
  ConfirmarPresencaController controller = Modular.get();

  ConfirmarPresencaWidget({Key key, this.parentAction}) : super(key: key);
  //var mask = MaskedTextController(mask: '(00) 0 0000.0000');

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: new Text("Confirme sua presença"),
      content: Container(
        child: Container(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              //*NOME E SOBRENOME
              TextField(
                onChanged: (value) {
                  controller.nome = value;
                  controller.checkIsValid();
                },
                maxLength: 30,
                decoration: InputDecoration(
                    labelText: 'Nome e sobrenome',
                    counterStyle: TextStyle(fontSize: 0)),
              ),
              //* TELEFONE
              TextField(
                //TODO verificar possível troca da máscara: parece não ter suporte WEB
                //controller: mask,
                onChanged: (value) {
                  controller.telefone = value;
                  controller.checkIsValid();
                },
                keyboardType: TextInputType.number,
                inputFormatters: <TextInputFormatter>[
                  WhitelistingTextInputFormatter.digitsOnly
                ],
                decoration: InputDecoration(
                    labelText: 'Telefone',
                    counterStyle: TextStyle(fontSize: 0)),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 30),
              ),
              //* QUANTIDADE DE ADULTOS E CRIANCAS
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Column(
                    children: <Widget>[
                      Text('adultos'),
                      QuantidadeInputWidget(
                        parentAction: controller.setAdultos,
                        value: 1,
                      ),
                    ],
                  ),
                  Column(
                    children: <Widget>[
                      Text('crianças'),
                      QuantidadeInputWidget(
                        parentAction: controller.setCriancas,
                        value: 0,
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
      actions: <Widget>[
        //* define os botões na base do dialogo
        RaisedButton(
          color: Colors.blue,
          child: new Text("Cancelar"),
          onPressed: () async {
            Navigator.of(context).pop();
          },
        ),
        Observer(builder: (_) {
          return RaisedButton(
            color: Colors.blue,
            child: new Text("Enviar"),
            onPressed: controller.isValid
                ? () async {
                    var result = await controller.enviarConfirmacao();

                    Navigator.pop(context);
                  }
                : null,
          );
        }),
      ],
    );
  }
}

1 answer

0


Are you using the await therefore, your method will be blocked waiting until the Future returned by controller.enviarConfirmacao() be completed. Only then to execute the next instruction, which is to close the dialog.

You haven’t put the code of this method, but it seems to me that it’s not returning anything, not completing yours Future. And he shall return.

Try to think of a better solution because this way you are freezing the screen for the user without a loading or any information that has a processing being done.

  • Thank you. Really, the problem was the return of this method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.