Home > Enterprise >  How to not show the selected dropdown item in flutter
How to not show the selected dropdown item in flutter

Time:01-17

How to not show the selected item in the dropdown? I m using DropdownButtonHideUnderline package in flutter to implement a dropdown but i don't want to show the selected item on the top.And i just need the selected item in a variable .How to do this?

Please help..

DropdownButtonHideUnderline(
    child: DropdownButton2(
  // Initial Value
  value: dropdownValue,

  // Down Arrow Icon
  icon: const Icon(
    Icons.more_vert,
    color: Colors.white,
  ),

  // Array list of items
  items: items.map((String items) {
    return DropdownMenuItem(
      value: items,
      child: Text(
        items,
        style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
      ),
    );
  }).toList(),
  // After selecting the desired option,it will
  // change button value to selected value
  onChanged: (String? newValue) {
    setState(() {
      dropdownValue = newValue!;
    });
  },
))

CodePudding user response:

here you change the selected value:

 onChanged: (String? newValue) {
                                  setState(() {
                                    dropdownValue = newValue!;
                                  });
}

by removing

setState(() {
                                    dropdownValue = newValue!;
                                  });

your dropdown will not change.

and you can use the chosen value by

onChanged: (String? newValue) => doSomething(newValue),
Future<void> doSomething(String? value) async {
...
}

CodePudding user response:

You can ignore setting value on onChanged,

here, remove this, this is used to update the value on dropdownButton .

onChanged: (String? newValue) {
  // setState(() {
  //   dropdownValue = newValue!;
  // });
},
  • Related