Issue
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 = [
'Default',
'Difficulty',
'Time',
'Distance',
];
RxInt selectedIndex = 0.obs;
…
Obx(() => DropdownButton(
value: dropdownvalue.value,
items: items.map((String items) {
return DropdownMenuItem(
value: items,
child: Text(items),
);
}).toList(),
onChanged: (value) {
dropdownvalue.value = value.toString();
},
)
This is how it looks now:
The list should stay in one place when its opened, and values should change places.
Solution
you should rearrange your list after selecting an item
onChanged: (value) {
dropdownvalue.value = value.toString();
items.remove("Time");
items.insert(0, "Time");
setState((){});
},
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.