[SOLVED] Flutter dropdown button selected value position


This Content is from Stack Overflow. Question asked by Gryva

How can I make the selected dropdown item appear first in the list when its opened?
I’m using GetX for state,

is this the proper way of doing it anyway?

This is the code:

var dropdownvalue = 'Default'.obs;
  var items = [
  RxInt selectedIndex = 0.obs;

Obx(() => DropdownButton(
                    value: dropdownvalue.value,
                    items: items.map((String items) {
                      return DropdownMenuItem(
                        value: items,
                        child: Text(items),
                    onChanged: (value) {
                      dropdownvalue.value = value.toString();

This is how it looks now:

enter image description here

The list should stay in one place when its opened, and values should change places.


you should rearrange your list after selecting an item

onChanged: (value) {
  dropdownvalue.value = value.toString();
  items.insert(0, "Time");

This Question was asked in StackOverflow by Gryva and Answered by Ahmed Mohamed It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?