searchable_dropdown
searchable_dropdown copied to clipboard
Search not working when working with List<DropdownMenuItem<Model>>
I'm not sure why, I get the text displayed but it just doesnt work. Here is the code and some screenshots. ` formarPaises() async { List<PaisModel> pm = new List<PaisModel>(); paises = List<DropdownMenuItem<PaisModel>>();
await http.get(url + '/paises',
headers: {
'Accept': 'application/json'
})
.then((http.Response res) async {
Map<String, dynamic> jsonr = json.decode(res.body);
if (res.statusCode < 200 || res.statusCode > 400) {
Fluttertoast.showToast(
msg: "Error al obtener los paises",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 2,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
} else {
jsonr["data"].forEach((dd) {
pm.add(new PaisModel.map(dd));
});
}
}).then((a) async {
setState(() {
paisModel = null;
paises = paisDropDownItems(pm);
});
});
}`
List<DropdownMenuItem<PaisModel>> paisDropDownItems(List<PaisModel> list) { List<DropdownMenuItem<PaisModel>> items = List(); for (PaisModel paisModel in list) { items.add( DropdownMenuItem( value: paisModel, child: Text(paisModel.Descripcion), ), ); } return items; }
Those two are to form the searchlist and to show it its this:
Card( elevation: 3, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(5.0), ), ), child: SearchableDropdown.single( iconEnabledColor: Colors.blue, iconDisabledColor: Colors.blue, displayClearIcon: false, underline: Container(), selectedValueWidgetFn: (t) { return Container( transform: Matrix4.translationValues(0,0,0), alignment: Alignment.centerLeft, child: (Text(paisModel.Descripcion))); }, hint: "Pais *", searchHint: "Pais *", value: paisModel, items: paises, onChanged: (v) { setState(() { paisModel = v; formarProvincias(v.PaisID); changeFocus(provinciaIDFocusNode); }); }, isExpanded: true, ), ), ),
The result is the next
but when I search
Here its another result with the same example but another api.
What am I missing here?
Maybe its cuz I'm using a old version of flutter? (Wich I need for this proyect :( )
This can happen when Your drop down value and child are not the same
This can happen when Your drop down value and child are not the same
I mean of course they are not the same, the value is the entire model, with the ID, description, etc, etc, and the child has to be a text or I'm wrong?
@darkrevenger am facing the same issue did you get the solution? search is not working
I found it you have put text in value field also so when you will search it will search according to text
in my case what i did
search works with "value" field
I found it you have put text in value field also so when you will search it will search according to text in my case what i did
search works with "value" field
Value in my case is the string you are providing in text widget
@WaheedHussainHaans its okay don't pass the Text widget, later i updated to string which was
Value : name + "," + id
I put both name n id so that it will work for search and i ll get the id also for later purpose.
if you are using class to forget to add toString override
@override String toString() { return this.name; }