searchable_dropdown icon indicating copy to clipboard operation
searchable_dropdown copied to clipboard

Search not working when working with List<DropdownMenuItem<Model>>

Open darkrevenger opened this issue 4 years ago • 8 comments

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 image but when I search image Here its another result with the same example but another api. image image What am I missing here?

darkrevenger avatar Jun 29 '20 15:06 darkrevenger

Maybe its cuz I'm using a old version of flutter? (Wich I need for this proyect :( )

darkrevenger avatar Jun 30 '20 15:06 darkrevenger

This can happen when Your drop down value and child are not the same

WaheedHussainHaans avatar Jul 15 '20 16:07 WaheedHussainHaans

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 avatar Jul 15 '20 23:07 darkrevenger

@darkrevenger am facing the same issue did you get the solution? search is not working image image

irzum avatar Jul 29 '20 12:07 irzum

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 image search works with "value" field image

irzum avatar Jul 29 '20 13:07 irzum

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 image search works with "value" field image

Value in my case is the string you are providing in text widget

WaheedHussainHaans avatar Jul 29 '20 15:07 WaheedHussainHaans

@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.

irzum avatar Jul 29 '20 16:07 irzum

if you are using class to forget to add toString override

@override String toString() { return this.name; }

mrazaimtiaz avatar Nov 24 '20 07:11 mrazaimtiaz