Home > Software engineering >  flutter dropdownbutton initial value doesn't change on screen
flutter dropdownbutton initial value doesn't change on screen

Time:06-09

I have dropdownbutton and items coming dynamic list thats perfectly works. i can show all list item but when i select someone my value doesn't change on the screen. just entry.first write doesn't change to which is selected. when i check on the terminal i can see the selected item so set state method works but initialvalue doesn't change.

my dropdown button

 String dropdownvalue = entry.first;  
 var items =entry;
 DropdownButton(
           
          // Initial Value
       value: dropdownvalue,
           
          // Down Arrow Icon
          icon: const Icon(Icons.keyboard_arrow_down),   
           
          // Array list of items
          items: items.map((dynamic items) {
            return DropdownMenuItem(
              value: items,
              child: Text(items),
            );
          }).toList(),
          // After selecting the desired option,it will
          // change button value to selected value
          onChanged: (dynamic newvalue) {
            setState(() {
              dropdownvalue = newvalue; > **this not working**
            print(dropdownvalue); > **it gives the newvalue**
             });
          },
        ),

CodePudding user response:

It seems that your issue is related to the way how you have declared the dropdownvalue and items list.

Please check this dartpad out. Here I'm using you code with some modifications for the declaration of items list and dropdownvalue.

https://dartpad.dev/?id=33ef41ea7fa95613fe1a498e4dac4bcc

  • Related