Flutter handle scroll actions (PrimaryScrollController reverse listview)

652 views Asked by At

On iOS, tapping the status bar makes PrimaryScrollController go to the top: https://flutter.dev/docs/resources/platform-adaptations#return-to-top

On iOS, tapping the OS status bar scrolls the primary scroll controller to the top position. There is no equivalent behavior on Android.

My PrimaryScrollController is attached to a ListView with reverse:true, so tapping the status bar makes it scroll to the bottom.

Docs say PrimaryScrollView handles ScrollAction if not handled by another scroll controller. https://api.flutter.dev/flutter/widgets/PrimaryScrollController-class.html

If a ScrollAction is not handled by an otherwise focused part of the application, the ScrollAction will be evaluated using the scroll view associated with a PrimaryScrollController

How can I handle scroll actions myself so I can reverse the direction PrimaryScrollController goes when the status bar is tapped?

1

There are 1 answers

2
Alex Hartford On

The easiest way to accomplish this is likely going to be reversing the items in your list instead of using the reverse: true flag of ListView.

For example:

ListView(
  children: [
    Container(),
    Container(),
  ].reversed.toList(),
),

Trying to solve this any other way would get pretty involved. Since we don't have access to the StatusBar we can't override its behavior or listen for taps on it.