Skip to content

Scrolling to a selected GroupedListView index/item #213

@DennisH511

Description

@DennisH511

Context:
I have a ListView and I'm using the scrollview_observer package to automatically scroll the selected index to the top of the list when selected. Everything works as expected.

List data:

final List<MyEvent> _myEventsList = [
    MyEvent(date: DateTime(2019, 1, 1)),
    MyEvent(date: DateTime(2019, 2, 1)),
    MyEvent(date: DateTime(2019, 3, 1)),
    MyEvent(date: DateTime(2020, 1, 1)),
    MyEvent(date: DateTime(2020, 2, 1)),
    MyEvent(date: DateTime(2020, 3, 1)),
    MyEvent(date: DateTime(2020, 4, 1)),
  ];

Issue:
When I replace the ListView with a GroupedListView, grouping the items by the event year and try to scroll to the selected index, the list scrolls but not to the correct position for the selected item. The grouped items have the correct index.

For the example data, if I select the item with index 4, the list scrolls to the top of the item with index 2.

Counting from the top of the list, the item with index 2 is the 4th item if you include the 2 group headers.

Screenshot

Any help is appreciated.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions