Open milesegan opened 1 year ago
hi @milesegan! I will look into this but I was curious what was the use case that generated this issue, like why did you change the length of the children and then pointed to one that wasn't on the list? This would help me understand better how the API should solve your issue without breaking changes 👍
@marcossevilla In my case I have a responsive app that has a different number of items depending on whether it's on a small or a large screen. So when the user resizes the app from small to large the number of items in the stack increases. Maybe this is an unusual situation?
In any case I think you could make this change to the implementation without changing anything in the API of LazyIndexedStack
.
@milesegan sorry for the late reply, I can try reassigning the children on didUpdateWidget if they change but this would reset the stack active children. would that be the behavior you're expecting?
@marcossevilla Thanks for the reply. I've been using a patched version of the stack storing them in a set instead of a list like this:
late final _activatedChildren = <int>{widget.index};
This has been working well for me for a while now.
@milesegan alright, you feel that should be the way it's handled in the package? I don't really see advantages aside from your use case.
Well I think the main issue with the current implementation is that it's quite easy to crash the app.
Description The LazyIndexedStack can crash if the length of
children
changes.Steps To Reproduce
children
and then change the index to point to one of the new children._activatedChildren
list.https://github.com/marcossevilla/lazy_indexed_stack/blob/0d156173f7fa19a330178721ee2b51833a48f79d/lib/src/flutter_lazy_indexed_stack.dart#L37
Maybe it would be safer to use a set like this:
Thanks for the library by the way!