I need to listen for a tap event on the status bar and call a custom function (call Scrollable.ensureVisible). However, there is no way I can find a way to do this.
As far as I understand, there are 2 options:
- Listen to this event from flutter, but I haven’t found any way to do this.
- Write native code that will listen to the status bar tap event and use MethodChannel to deliver the event to dart.
All my attempts to implement both options failed. Could you please tell me how it can be done?
2
Answers
Use this package to achieve your goal https://pub.dev/packages/scrolls_to_top
Keep in mind that Flutter has the ability to render every pixel of your screen. So, to override the default tap action on the status bar you have to add a
GestureDetector
where the status bar is normally positioned.This can be achieved with a
Stack
where the first child is your main widget tree (usually aScaffold
) and the second child is aPositioned
with theGestureDetector
: