srtraj / dropdown_textfield

custom dropdown
MIT License
8 stars 48 forks source link

DropdownTextField search feature not calling onChange #60

Open amirudev opened 2 months ago

amirudev commented 2 months ago

I use DropdownTextField with having search feature by setting enableSearch to true, but when I select it, it doesn't call onChange which like selecting it items like usual

Without search feature, when selecting one of it items, it called onChange but its behaviour not achieved when selecting its item with search feature

DropDownTextField(
  textFieldDecoration: InputDecoration(
    border: InputBorder.none,
  ),
  dropDownList: state.employees
      .map(
        (e) => DropDownValueModel(
          name: e.name,
          value: e.id,
        ),
      )
      .toList(),
  onChanged: (value) {
    if (value == null || value == "") {
      selectedEmployee.value = Employee(
        id: '',
        code: '',
        name: '',
        idsPassword: '',
        email: '',
        department: '',
        departmentId: '',
      );

      return;
    }

    final valueDropdownValueModel =
        value as DropDownValueModel;

    // Find the selected employee from the list using the value
    final selected = state.employees.firstWhere(
          (employee) => employee.id == valueDropdownValueModel.value,
      orElse: () => Employee(
        id: '',
        code: '',
        name: '',
        idsPassword: '',
        email: '',
        department: '',
        departmentId: '',
      ),
    );

    // Update the selectedEmployee state with the new value
    selectedEmployee.value = selected;
  },
);