lazy_indexed_stack
lazy_indexed_stack copied to clipboard
Crash if length of children changes
Description
The LazyIndexedStack can crash if the length of children
changes.
Steps To Reproduce
- Render the widget.
- Change the length of
children
and then change the index to point to one of the new children. - The widget will crash trying to index past the end of the
_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:
late final _activatedChildren = <int>{widget.index};
Thanks for the library by the way!
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
.