-
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
initialValue not working as expected #5
Comments
Hi @jjoschyy, Thank you for submitting this issue. I can see that the chips do not get displayed on the default chipDisplay when an initialValue is set on the MultiSelectBottomSheetField. This will be fixed. I want to point out that the selected values in the bottomsheet will be set to initialValue every time you open it, even if you changed the selection! To provide background on this param: The In the case of MultiSelectBottomSheetField/MultiSelectDialogField, the initialValue param is not required as there is an internal list of selected items that is being passed from MultiSelectBottomSheetField to MultiSelectBottomSheet every time it is However, this param becomes useful when your MultiSelect widget is being re-inserted into the widget tree. For example if you have a MultiSelectDialogField inside of your own custom BottomSheet, you might:
Setting Basically the But what if you just want some pre-selected items the first time it is opened? I recommend following these steps to pre-select values before initial interaction:
Hope this helps :) |
Hello CHB61 Thanks a lot for your detailed answer. This helped me a lot. Also thanks for the fix. I can confirm the inital values are now shown correctly. Nevertheless, one issue seems still existing. After adding inital values, the remove action is not working anymore. Example: On this action, the selected value is removed from the _selected list. This works, the value will be removed from the _selected list. But there is no refresh on the MultiSelectChipDisplay. But if I manually select any other item from the list, the remove action works. I follwed your recommondation:
Thanks again for your help! |
@jjoschyy Hi! Sorry for the delay! Been so busy last couple weeks but I'll take a look into this problem ASAP. |
Hi @jjoschyy , Sorry for the delay on this one. I was able to reproduce the issue. The reason you can only delete from the chip display after doing a confirm is because in the onConfirm function, This means that only when you obtain a reference to the list that is provided in the onConfirm, can you manipulate it from onTap and then the changes will be updated.
So it also means that if you were to change the code in the onConfirm to something like:
Deleting from the chip display won't work at all now because there is no reference to the list that MultiSelectDialogField uses With onTap(V) all we know is which item was tapped, and there's no guarantee that the list is going to change. So in order to delete without getting a reference to the internal list, the fix I've applied is to have MultiSelectDialogField check if All you would need to do to is simply return the updated list in the onTap function. Example:
You don't even need to set state anymore. I was considering not passing by reference at all in the onConfirm since it wasn't intentional but I decided to leave that for now.
This change is available in version 3.1.4. Hope this helps :) |
@CHB61 Please open this issue again The issue is still exist for me, initialValue can't be shown |
This was not working for me neither because I followed the example of pub.dev that is using the class without the Generics, like:
instead of:
following the repo example generics use, my |
@CHB61 I've got issues having initial values because I'm setting them asynchronously, but these values are being set on |
I have the same problem. |
Hi,it helps for me , but now I am unable to get values from list, it shows instances. |
@MuhammadSufyanMalik could you help me in this one onTap: (value) {
|
Hello CHB61
Thanks for this great flutter lib.
Seems the initialValue property is not working correctly. Based on your example I added all animals as an initial value:
MultiSelectBottomSheetField( initialValue: _animals, ..... ),
As a result the selected animals are not shown inside the form. But all animals are pre-selected on the bottom selection area (see screenshot).
The text was updated successfully, but these errors were encountered: