• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Guillermo García

  • Podcast
  • Blog
  • Contactar

Dialog de confirmación

15 noviembre, 2021 by Guillermo García

Hay algunas acciones para las que queremos solicitar una confirmación del usuario, sobre todo a la hora de eliminar información. Para eso es normal utilizar un dialog con un mensaje informativo y un botón para confirmar la acción.

Lo podemos hacer con la siguiente función:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void showConfirmationDialog(BuildContext context) {
    // set up the buttons
    Widget cancelButton = TextButton(
      child: Text(AppLocalizations.of(context)!.cancel),
      onPressed:  () {
        Navigator.pop(context);
      },
    );
    Widget continueButton = TextButton(
      child: Text(AppLocalizations.of(context)!.delete),
      onPressed:  (){
        //Do the action!
      },
    );
    // set up the AlertDialog
    AlertDialog alert = AlertDialog(
      content: Text(AppLocalizations.of(context)!.confirmationMessage),
      actions: [
        cancelButton,
        continueButton,
      ],
    );
    // show the dialog
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }

Filed Under: Tutoriales de Flutter

sidebar

sidebar-alt