Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing a selected item #83

Open
Ivan-Wabuyobo opened this issue Jul 11, 2024 · 5 comments
Open

Clearing a selected item #83

Ivan-Wabuyobo opened this issue Jul 11, 2024 · 5 comments

Comments

@Ivan-Wabuyobo
Copy link

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
Copy link

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

@AbdullahChauhan
Copy link
Owner

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

@rymesaint
Copy link

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
Copy link
Owner

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
Copy link

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

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants