My DropDown working fine. I can Select item from my dropdown and also showing the selected item in my App. Now, Instead of displaying the selected item from dropdown I want to display index number of that particular Item.
My Dropdown item List
List<String> qualities = [
"Creativity",
"Commitment",
"Planning",
"Optimism",
"Innovative"
];
Empty List. Here I'm storing selected items, then displaying using for loop
List<String> selectedItem_ArrayList = []; //Storing DropDown selected data
My dropDown
DropdownButton<String>(
underline: Container(),
icon: Icon(Icons.keyboard_arrow_down),
iconSize: 24,
isExpanded: true,
onChanged: (value) {
if (!selectedItem_ArrayList.contains(value)) {//=============================================>>>Items Disable after selection
setState(() {
selectedQualities = value!;
selectedItem_ArrayList.add(selectedQualities);
});
}//==============================================>>>Adding item into list
},
value: selectedQualities,
items: qualities.map((dropdownValue) => DropdownMenuItem(
child: Text(
dropdownValue,
maxLines: 2,
style: TextStyle(
color: selectedItem_ArrayList.contains(dropdownValue)? Colors.grey: null,
),
),
value: dropdownValue,
))
.toList(),
),
Displaying Selected Item from drop Dropdown
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (var i = 0; i < selectedItem_ArrayList.length; i++)
ListTile(
title: Text(selectedItem_ArrayList[i]), //### here I want to show index number of that particular selected item.
trailing: GestureDetector(//#################### remove specific index item
onTap: () {
setState(() {
selectedItem_ArrayList.remove(selectedItem_ArrayList[i]);
});
},
child: Icon(
Icons.delete_rounded,
color: Colors.red,
),
),
),
],
)
Using indexOf its only displaing index number 0 for every item selection
title: Text(selectedItem_ArrayList[i].indexOf(selectedItem_ArrayList[i]).toString()),
