-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
[help] Implementing multiple selection with custom object #97
Comments
Also, another question: why the selection returns the indexes of selected values on the list instead of the values? Is there any way to have the list of |
Hello @Macacoazul01 , Thanks for raising this! Indeed, this is not ideal. I think this all comes down to the fact that SearchChoices is typed with T where T is the custom object type. This is valid for the single case but this creates issues for the multiple case where T should probably refer to the List of custom objects type. This seems like a good but quite transforming change. Here is my attempt at solving the sendSelection(dynamic selection, [BuildContext? onChangeContext]) {
try {
if(selection is List<int> && ! (widget.items?.first.value is List<int>)) {//trying to address the multiple case warning
didChange(selection.map((i) => widget.items?[i].value,).toList());
}
else {
didChange(selection);
}
} catch (e, st) {
debugPrint(
"Warning: didChange call threw an error: ${e.toString()} ${st.toString()} You may want to reconsider the declared types otherwise the form validation may not consider this field properly.");
}
... But this generates this compilation error:
Solving this by changing the multiple case to take the list of objects as T seems like a long battle to me and I am not sure there are better alternatives. Now, still in multiple case, it should be possible to have a new |
In fact, in the multiple case, this line: class SearchChoices<T> extends FormField<T> { should probably be like this: class SearchChoices<T> extends FormField<List<T>> { but this would break the single case. |
I'm gonna try exploring this part of the package |
Thanks a lot @Macacoazul01 ! |
Thanks a lot @Macacoazul01 ! |
I had to interrupt while trying to integrate your custom objects examples in the list of examples. I will resume as soon as possible. |
I've found some problems trying to implement this sample on a different way because you wrap only in the middle of the code the materialapp. Gonna create another issue to attack this point. |
Oh, I see. I will leave it as it is then for now. |
In fact, I was able to integrate your example after some simplification. I hope you won't mind. |
… Thanks @Macacoazul01 #97 ; Separated big classes. Thanks @Macacoazul01 #100
Automated testing shows that example 41 (Validator in form) fails with the latest version. I am trying to understand why. |
I had to restore the call to the Form didChange in case of multiple selection but I reduced the warning message. |
Release 2.2.0 has just been published to pub.dev with the mentioned changes. Though, this doesn't fully solve yet the multiple cases form didChange calls. |
The way it is will still lead to the form warning, maybe you should maintain the old implementation with the warning being set on the else of if(!multiple selection) |
As the didchange will always lead to the error |
I changed the warning in the multiple selection case to display just this:
The |
Yes, I think this is a good idea that would solve your issue. Though, this is not solving all the cases and I would like to keep this issue open until this is solved. |
I'm having some problems on trying to implement multiple selection with a custom class.
Everything is rendered ok but on the console this log is printed:
Maybe i forgot to implement some function...
Here's the sample code, @lcuis:
multi select.zip
Can you help me?
The text was updated successfully, but these errors were encountered: