I have a dropdown button in which I am binding id to value and name to display Text. When user select an item from dropdown, I am getting the value using onChanged. How can I get the displayed text along with the value?
return Obx(() => DropdownButton(
focusColor: Colors.blue,
underline: SizedBox(),
isExpanded: true,
isDense: true,
hint: Text("Select from List"),
value: (fgTaskController.selectedFG.value == "")
? null
: fgTaskController.selectedFG.value,
items: fgTaskController.fgList.map((item) {
return DropdownMenuItem(
value: item.id,
child: new Text(
item.fgName.toString(),
style: GoogleFonts.notoSerif(
textStyle: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.blue,
)),
),
);
}).toList(),
onChanged: (newValue) {
fgTaskController.setSelectedFG(newValue);
_selectedFG = newValue!;
},
));
}```
My Data set is like this:
[
{
"fg_name": "fg_name 1",
"id": "1"
},
{
"fg_name": "fg_name 2",
"id": "2"
},
{
"fg_name": "fg_name 3",
"id": "3"
}]
fg_name is displayed to user. Value is id. I want to save the selected fg_name and id to a Listview. That is the purpose.