find_dropdown icon indicating copy to clipboard operation
find_dropdown copied to clipboard

onFind on press back button on android display [No data found]

Open fnoceda opened this issue 3 years ago • 0 comments

HI, i have a problem, i need implemented with a model, al is fine, but when i find on the text searchBox, the result return the list of data but when i press in the phone back button for scrolling mi new list, the results display [No data found] This is my code

Widget _UserModelDropFind(FormularioController _){

  return Obx((){
      if(_.isPrestadoresPrestaciones.value == true){
        return FindDropdown<UserModel>(
            items: _.prestadoresPrestaciones,
            label: "Prestador *",
            onChanged: (UserModel value) {
                _.setUserModel(value);
            },
            selectedItem: _.UserModel,
            labelStyle: TextStyle(
                color: Colors.grey[600], fontSize: 18, fontWeight: FontWeight.w300),
            searchBoxDecoration: InputDecoration(hintText: "Buscar..."),
            titleStyle: TextStyle(color: Colors.indigo[700].withRed(80)),

            dropdownBuilder: (BuildContext context, UserModel item) {
                print('Se esta ejecutando dropdownBuilder');
                return Container(
                decoration: BoxDecoration(
                    border: Border.all(color: Theme.of(context).dividerColor),
                    borderRadius: BorderRadius.circular(5),
                    color: Colors.white,
                ),
                child: (item == null)
                    ? ListTile(title: Text("Elija al prestador"), dense: true)
                    : ListTile(
                        dense: true,
                        title: Text(item.nomprestador),
                        subtitle: Text(item.nomprestacion),
                        ),
                );
            },
            dropdownItemBuilder: (BuildContext context, UserModel item, bool isSelected) {
                print('Se esta ejecutando dropdownItemBuilder');
                return Container(
                    decoration: !isSelected
                        ? null
                        : BoxDecoration(
                            border: Border.all(color: Theme.of(context).primaryColor),
                            borderRadius: BorderRadius.circular(5),
                            color: Colors.white,
                            ),
                    child: ListTile(
                        selected: isSelected,
                        title: Text(item.nomprestador),
                        subtitle: Text(item.nomprestacion),
                    ),
                );
            },
            onFind: (String filtro) => _findData(filtro, _),
        );
    }
    return Container();
  });

}

Future<List<UserModel>> _findData(String filtro, FormularioController _) async{
    print('se esta ejecutando _findData');
    print(filtro.toUpperCase());
    List<UserModel> data = [];
    // List<UserModel> data = _.prestadoresPrestaciones.where((UserModel item) => item.nomprestador.toUpperCase().contains(filtro.toUpperCase())).toList();

    if (_.prestadoresPrestaciones.any((element) => element.nomprestador.toLowerCase().contains(filtro.toLowerCase()))) {
        data =  _.prestadoresPrestaciones
            .where((element) =>
                element.nomprestador.toLowerCase().contains(filtro.toLowerCase()))
            .toList();

    }
    print( 'data.length =>' + data.length.toString());
    return data;
}

i apreciate your help.

fnoceda avatar Apr 02 '21 21:04 fnoceda