I’m new on Flutter, and i’m trying to do a simple thing: have a selection list with multi choices.
I’m a web developer and this is a native feature usually, but i discovered that’s not the case in Flutter.
I’ve tried to find a good plugin for that, and discovered animated_custom_dropdown.
My problem is that the dropdown doesn’t save any choice. As i’m new on Flutter, i think i’ve some context/state problem, but I can’t figure out which one. I don’t understand what I’m doing wrong.
Choice is not saved
Could someone help me understand or provide a link or example that would help me?
If you know of a better library for simply having a multi-selection dropdown from a future, I’d be interested too!
Thanks in advance!
My current code is basically this:
class _HomeScreenState extends State<HomeScreen>
with AfterLayoutMixin<HomeScreen> {
final SkillRepository _skillRepository = injector.get();
// ...
List<Skill> _selectedSkills = [];
// ...
Future<List<Skill>> _getSkills() async {
return await _skillRepository.retrieveAll();
}
// ...
FutureBuilder(
future: _getSkills(),
builder:
(BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return CustomDropdown<Skill>.multiSelect(
hintText: 'Compétences',
items: snapshot.data.toList(),
onListChanged: (value) => setState(() {
log('changing value to: $value');
_selectedSkills = value;
}));
} else {
return const CircularProgressIndicator();
}
}),
user26585370 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You must add Controller property to control the selected item
Here’s the doc, check the 4th property
animated_custom_dropdown library api doc