I have 4 different dropdown fields with 5 options and I want to disable/remove an option from other fields if the option is already selected.
Screenshot: Screenshot 1 Screenshot 2
DropDown Menu Code:
String opemo1, opemo2, opemo3, opemo4; List<String> emoji = [ "❤️", "", "✌️", "", "", ];
DropdownButtonFormField( validator: (value) => value == null? 'required': null, hint: Text('❤️'), value: opemo1, icon: Icon(Icons.arrow_drop_down), iconSize: 36, isExpanded: true, style: TextType.regularDarkText, onChanged: (newValue) { setState(() { opemo1 = newValue; pollDataController.setop1Emoji(newValue); }); }, items: emoji.map((opemo1) { return DropdownMenuItem( value: opemo1, child: Text(opemo1), ); }).toList(), ),
To manage it you need to remove the selected emoji from List<String> emoji
.
onChanged: (newValue) {
setState(() {
emoji.removeWhere((element) => element == newValue); /// This removed selected emoji.
opemo1 = newValue;
pollDataController.setop1Emoji(newValue);
});
},
You can replace your onChanged
with this snippet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.