Home > front end >  DropdownButtonFormField not showing Drop down Menu Items
DropdownButtonFormField not showing Drop down Menu Items

Time:10-18

this is my code

  Padding(
                    padding: EdgeInsets.symmetric(vertical: 10.h),
                    child: DropdownButtonFormField(
                      decoration: InputDecoration(
                          labelText: "countries",
                          labelStyle: TextStyle(fontSize: 16.sp),
                          border: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(10))),
                      items: const [
                        
                        DropdownMenuItem(child: Text("USA"), value: "USA"),
                        DropdownMenuItem(
                            child: Text("Canada"), value: "Canada"),
                        DropdownMenuItem(
                            child: Text("Brazil"), value: "Brazil"),
                        DropdownMenuItem(
                            child: Text("England"), value: "England"),
                      ],
                    ),
                  ),

when i click on DropDownButtonFormField the items does not appear .

CodePudding user response:

A common mistake when it is not updating is to use DropdownButtonFormField in a StatelessWidget rather than a StatefulWidget. but hard to say as you did not share that part of the code

Seems you are also missing other code in your DropdownButtonFormField

DropdownButtonFormField(
    value: myVariable,
    onChanged: (value) {
              setState(() {
                myVariable= value;
              });
            },

Let me know if this does not help.

CodePudding user response:

Anything with an interaction with user must be inside StatefulWidget. There is another ways like changenotifier using notifyListeners() inside void function. https://medium.com/@aruny3/how-to-use-changenotifier-in-flutter-440371617b8c

  • Related