-
Notifications
You must be signed in to change notification settings - Fork 229
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
Add a way to programmatically change the selected items #12
Comments
@victorcatn Hello, Can you clarify how you would like to manage the selected items and which widget you are trying to do this with? Typically, I'll have my own list of selected items set as the initialValue, and just manage that. |
#40 I was able to do it by modifying the build method of the widget refer to the issue motioned. In bloc architecture it is not possible to maintain the same reference value as with each sate change entire new object is created with a new reference. So unless the internal reference of the _selectedItems is updated it will not be possible to modify it in the bloc architecture . |
@CHB61 Are you planning to work on this issue, please? |
If your goal is to update the selected items by clicking on the chip, It can be done by returning the updated value at the MultiSelectChipDiplay::onTap method, like so:
|
I think the thing that people are asking for is some kind of controller to programmatically change the content of the selected items. Currently I think the reason people are having problems is because "initialValue" is the only way to set the internal state without selecting things from a dialog or sheet. In multi_sellect_dialog_field.dart its only use is
this doesn't allow for changing the internal state after the widget has been created. It would be nice if there were a way to do this without manually destroying the widget and rebuilding it. |
Seconded - I need this ability. @Darksoulsong I tried adding the |
Thanks for the PR niccord! Can anyone with permissions please review the PR and approve to get this added functionality? I would need it but am happy to help if I can :) |
I solved this problem by interfering with the library. This works for me. Here, I have run my code by triggering it under any method. Good job everyone, hope it works for you. |
How do you manually destroy and rebuild it? |
Set the 'key' parameter to GlobalKey(). Ex:
|
@asanet Can You help me in programmatically change the selected items? |
Hi @prkhrv ! I am doing this way:
Everytime I want to change the selected values, I change the variable "_selectedValues" then I call setState. This only works with you attribute the GLobalKey() to the parameter "key" in MultiSelectChipField. Hope it helps! |
@asanet Thanks a Lot! |
Thank you guy. I think that is best solution for the moment. |
Great, Thanks brother. It works. |
Hi,
I need to chage the selected items programmatically this widget but I don't found a way to do this after setting the initial items parameter.
The only way I can make this kind of changes is creating a new unique key for each rebuild, making flutter discard the old state and create a new from the initial items but I think it is not very efficient.
Thank you.
The text was updated successfully, but these errors were encountered: