AbdullahChauhan / custom-dropdown

Custom dropdown widget allows to add highly customizable dropdown widget in your projects. Features includes Search on list data, Network search, Multi-selection and many more.
https://pub.dev/packages/animated_custom_dropdown
BSD 3-Clause "New" or "Revised" License
155 stars 72 forks source link

Clearing a selected item #83

Open Ivan-Wabuyobo opened 4 months ago

Ivan-Wabuyobo commented 4 months ago

How do I clear an item that i have selected. I have to tried using the method clear() provided by the controller but it doesn't seem to come.

rymesaint commented 3 months ago

i'm having this problem too, is there any update on this

AbdullahChauhan commented 3 months ago

Hey @Ivan-Wabuyobo @rymesaint Thanks for your concern. Please share the code so I can look why this issue is occurring!

rymesaint commented 3 months ago

I therefore need a button to remove the value that was chosen. How can I do this?

CustomDropdown(
  items: _statuses,
  headerBuilder: (context, selectedItem, enabled) =>
      selectedItem.child,
  listItemBuilder: (context, item, isSelected, onItemSelect) =>
      item.child,
  initialItem: _statuses.firstWhereOrNull(
    (element) => element.value == _status.value,
  ),
  hintText: 'Status',
  onChanged: _changeStatus,
),
AbdullahChauhan commented 3 months ago

Try this code. Package version: 3.1.1

const List<String> _list = [
  'Developer',
  'Designer',
  'Consultant',
  'Student',
];

class ControllerCustomDropdown extends StatefulWidget {
  const ControllerCustomDropdown({Key? key}) : super(key: key);

  @override
  State<ControllerCustomDropdown> createState() =>
      _ControllerCustomDropdownState();
}

class _ControllerCustomDropdownState extends State<ControllerCustomDropdown> {
  final controller = SingleSelectController<String>(null);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        CustomDropdown(
          controller: controller,
          items: _list,
          onChanged: (value) {
            log('onChanged value: $value');
          },
        ),
        ElevatedButton(
          onPressed: () {
            controller.clear();
          },
          child: const Text('Clear'),
        ),
      ],
    );
  }
}
Paroca72 commented 1 month ago

Hello, I think should be a feature of the component as it seems something very used.

Thanks