Skip to content

ScrollablePositionedList: The can't be any widget with a GlobalKey in the list. #137

Open
@marcglasberg

Description

@marcglasberg

Suppose the list shows some widget with a GlobalKey as a list item, or somewhere in the widget tree of the list item.

There are 3 possibilities:

  1. When you scroll a small amount, it will just scroll, and not do any fade. It works great.

  2. When you scroll a large amount, it will start scrolling both the front list and the back list while it fades from one to the other. This works great.

  3. But when you scroll just the exact amount, it will start scrolling both the front list and the back list and do the fade, but now the lists are similar and it may be that the same widget appears in both the from list and the back list. If this key has a GlobalKey, it will throw an error, of course, because it cannot have two widgets in the tree with the same GlobalKey:

════════ Exception caught by widgets library ════════
The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.

The key Instance of 'MultipleGlobalObjectKey<_MyWidgetState>' was used by multiple widgets. The parents of those widgets were:
- Column(direction: vertical, mainAxisAlignment: start, crossAxisAlignment: center, renderObject: RenderFlex#bcd37 relayoutBoundary=up7)
- Column(direction: vertical, mainAxisAlignment: start, crossAxisAlignment: center, renderObject: RenderFlex#68b18 relayoutBoundary=up7 NEEDS-PAINT)
A GlobalKey can only be specified on one widget at a time in the widget tree.
When the exception was thrown, this was the stack: 
...

This is worst than it seems, because it means no widgets with a GlobalKey can be anywhere inside of an item, ever.

There are two solutions to this:

Solution 1) Document that the list cannot have any widgets with a GlobalKey. That's an important limitation, and makes using the list harder.

Solution 2) Make sure you never fade between the front and back lists if they will overlap each other. In this case, you should just scroll normally. In other words, you make sure a widget can never be in both lista at the same time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions