Closed anqit closed 7 months ago
Hello @anqit and thanks for pointing out the issue !
The real issue here is that the MultipleSearchSelectionController
throws LateInitializationError
which is obviously not intended.
Thanks and sorry for any incovenience that this may have caused ✌️
@anqit Can you try changing how you call the method ?
suffixIcon: IconButton(
onPressed: () {
controller.clearSearchField();
}, // Change here
icon: const Icon(
Icons.clear,
),
),
Because the old way was calling the method while the widget was not yet built.
@anqit Can you try changing how you call the method ?
suffixIcon: IconButton( onPressed: () { controller.clearSearchField(); }, // Change here icon: const Icon( Icons.clear, ), ),
Because the old way was calling the method while the widget was not yet built.
I'm guessing that would work, but I don't think that should be necessary. What if instead of each of the controller's methods being late initialized, the controller was assigned a late initialized reference to the search selection when the box is created? I think it would fix this problem, and semantically be more correct, because calling the methods would fail if the controller is never assigned. Something like:
class MultipleSearchSelectionController {
late final MultipleSearchSelection selectionWidget;
void setWidget(MultipleSearchSelection selectionWidget) { this.selectionWidget = selectionWidget; }
void clearSelection() { selectionWidget.clearSelection(); }
// .... other hooks
}
and then in the MultipleSearchSelection
constructor:
MultipleSearchSelection._(
// others
MultipleSearchSelectionController? controller,
) controller = controller ?? MultipleSearchSelectionController() {
controller.setWidget(this);
}
syntax might be off, but something like that?
Also, and I can open a separate issue if you think that would be better, but any thoughts to bringing back the other properties and having a default TextField
?
I'll look into your suggestion if it could work, I haven't seen similiar pattern again to be honest.
Also, and I can open a separate issue if you think that would be better, but any thoughts to bringing back the other properties and having a default
TextField
?
Yes please do if it is not a big deal for you.
@anqit I have refactored the MultipleSearchController
. You will no longer get the LateInitializationErrors
with version 2.6.2
🥂
I tried upgrading again, but now getting The Scrollbar's ScrollController has no ScrollPosition attached
when trying to scroll the shown items. I can open a separate issue, but curious if you or anyone else has noticed that?
@anqit can you please give me a minimal reproducable code ??
Yeah definitely, I'll create a new issue with that.
Is your feature request related to a problem?
I'm having a couple of issues with the latest update that removes search field options and instead requires an entire
TextField
instead. I like the thought of adding more flexibility to the field, however this seems a bit heavy handed to me. To try to get this to work, I've basically had to dig through the older version of the code and copy and paste the text field that was previously being built. My first issue with this is that now, instead of having to provide just a few options that were of interest to me, I now have to provide the entire TextField. Again, I appreciate the flexibility, but now there is no ability to rely on default options that made things easier to use. Second, I'm trying to recreate the previously available behavior of being able to clear the search field withshowClearSearchFieldButton
. It used to be you could just set that totrue
and everything would work as expected. However, now you have to create theIconButton
yourself and use theMultipleSearchSelectionController
to clear the search field. But, it turns out that the controller's function isn't set until you initialize theMultipleSearchSelection
itself, so this seems like a circular dependency to me. Here's basically what I am trying to do (irrelevant code is deleted):I guess the point of this issue is to see if you'd be willing to have it so you can provide the options individually as before, or if you wanted to provide the entire text field, to be able to do that as well, and default to the text field if it is provided, otherwise do the previous behavior. I am also curious to know how to recreate the clear search field button when the controller function has not been initialized.
Thanks!