DropdownButton dosnt update in a AlertDialog

it updates the variable but dosnt render with the new value

//user permitions dropdown variables

String gestion_medica_dropdown = ‘Flutter Code Sample’;

//edit dialog

  Future<void> _editModal() async {

    return showDialog<void>(

      context: context,

      barrierDismissible: false, // user must tap button!

      builder: (BuildContext context) {

        return AlertDialog(

          title: Text('Editando: '),

          content: SingleChildScrollView(

            child: ListBody(

              children: <Widget>[

                DropdownButton<String>(

                  value: gestion_medica_dropdown,

                  icon: Icon(Icons.arrow_downward),

                  iconSize: 24,

                  elevation: 16,

                  style: TextStyle(color: Colors.deepPurple),

                  underline: Container(

                    height: 2,

                    color: Colors.deepPurpleAccent,

                  ),

                  onChanged: (String newValue) {

                    setState(() {

                      gestion_medica_dropdown = newValue;

                    });

                    print(gestion_medica_dropdown);

                  },

                  items: <String>['Flutter Code Sample', 'true', 'false']

                      .map<DropdownMenuItem<String>>((String value) {

                    return DropdownMenuItem<String>(

                      value: value,

                      child: Text(value),

                    );

                  }).toList(),

                ),

                Text('You\’re like me. I’m never satisfied.'),

              ],

            ),

          ),

          actions: <Widget>[

            FlatButton(

                child: Text("Cancelar"),

                onPressed: () {

                  Navigator.of(context).pop();

                }),

            FlatButton(

              child: Text('Actualizar'),

              onPressed: () {

                Navigator.of(context).pop();

              },

            ),

          ],

        );

      },

    );

  }

Hey @Illud_Harpyja . Whenever you want to update something inside an Alert Dialog, you should wrap your Alert Dialog with StatefulBuilder.

https://api.flutter.dev/flutter/widgets/StatefulBuilder-class.html

Please try this and let us know if it helps! :slight_smile:

6 Likes

Hello sorry for taking to long to reply yeah i fixed thanks.

1 Like

How it fixed?
I can’t fixed this problem

have you tried the above suggestion?

This answer works, thank yoU!

1 Like