SanjaySodani / multiselect_dropdown_flutter

A simple multiselect dropdown with select all and search options. Works with a simple list and a list of maps.
BSD 3-Clause "New" or "Revised" License
11 stars 4 forks source link

How to provide non const list to the list parameter in MultiSelectDropdown #2

Closed Pranavantariot closed 1 year ago

Pranavantariot commented 1 year ago

hi i wanted to provide a non-const list to the list parameter but after providing a non-const list the dropdown is not generating

hycinth commented 1 year ago

i have the same problem, how to deal it?

SanjaySodani commented 1 year ago

i have the same problem, how to deal it?

@hycinth ... If I have understood your problem correctly then, the constructor of the multi select widget is const and its a stateful widget so you will not see the difference until its marked as dirty and rebuilds. Try providing UniqueKey() for the multi select widget.

Pranavantariot commented 1 year ago

The below code works for me you need to render the widget after API call hope this will solve your problem

details.isEmpty? 
null : 
MultiSelectDropdown.simpleList(
 list: details.map((e) => e.name) .toList(),
 initiallySelected: selectedDetails.map((e) => e.name).toList(),
 includeSelectAll: true,
 isLarge: false,
 textStyle: const TextStyle(fontSize: 14,overflow: TextOverflow.ellipsis),
 splashColor: Colors.transparent,
 onChange: (newList) {
 // your logic
 // typically setting state
 },
width: 180,
numberOfItemsLabelToShow: 2, // label to be shown for 2 items
padding: EdgeInsets.zero,
whenEmpty: 'Select Note', // text to show when selected list is empty
 boxDecoration: BoxDecoration( border: Border.all( color: Colors.transparent), borderRadius: BorderRadius.circular(0),),),