Skip to content

DropdownTextField search feature not calling onChange #60

@amirudev

Description

@amirudev

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;
  },
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions