Dropdown selection not displaying with Flutter

后端 未结 8 2117
攒了一身酷
攒了一身酷 2021-01-12 08:56

I\' m gettings items from JSON and displaying them in a dropdown. When the person select an item from the dropdown list, I get the selection but the selected item doesn\'t c

8条回答
  •  猫巷女王i
    2021-01-12 09:40

    This is the solution: "StatefulBuilder()"
    
           Future AgregarContacto() async {
                 String dropdownValue = 'Exento';
                 return showDialog(
               context: context,
               barrierDismissible: true, // user must tap button!
               builder: (BuildContext context) {
                     return StatefulBuilder(
                       builder: (BuildContext context, StateSetter setState) {
                       return AlertDialog(
                       title: Text('Agregar cliente', textAlign: TextAlign.center,),
                       content:
                         SingleChildScrollView(
                           child: ListBody(
                             children: [
                               Center(
                                 child: Material(
                                   type: MaterialType.transparency,
                                   child: DropdownButton(
                                     items: [
                                       'Responsable inscripto',
                                       'Monotributista',
                                       'Exento',
                                       'Consumidor final',
                                       'No responsable'
                                     ]
                                         .map>((
                                         String value) {
                                       return DropdownMenuItem(
                                         value: value,
                                         child: Text(value),
                                       ); //DropMenuItem
                                     }).toList(),
                                     value: dropdownValue,
                                     onChanged: (String newValue) {
                                       setState(() {
                                         dropdownValue = newValue;
                                         print("new${newValue}");
                                       }); //setState
                                     },
                                     //OnChange
                                     isExpanded: false,
                                     hint: Text('Responsable inscripto',
                                       style: TextStyle(color: Colors.black),),
                                   ),
                                 ), //Material
                               ), //Center
                             ],
                           ),
                         ),
                       actions: [
                             FlatButton(
                               child: Text('Regret'),
                               onPressed: () {
                                 Navigator.of(context).pop();
                              },
                           ),
                        ],
                     );
                }
                );
               },
             );
           }
    

提交回复
热议问题