Issue
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.
Edit: now it shows the same value
Solution
you should rearrange your list after selecting an item
onChanged: (value) {
dropdownvalue.value = value.toString();
items.remove("Time");
items.insert(0, "Time");
setState((){});
},
Answered By – Ahmed Mohamed
Answer Checked By – Robin (FlutterFixes Admin)