I have four tabs in bottomnavigation, i want to build functionally like Instagram when I tap on the home screen it brings the top of the home page For ex: I m on the home screen I scroll on the home screen then go to the second tab again come to the home screen by a tap on the bottom navigation screen is middle of the scroll but I tap again on home tap icon it will automatically scroll to top. I m using indexStack
for bottomnavigation
Any one has any idea about it?
2
Answers
You can use a ScrollController.
In the ListView or SingleChildScrollView (or whatever other scrollable widget) add controller.
Then if you want to get back to the top of the scrollview you can call
To get this functionality only on the second tap of the bottomappbar icon you can check if the index is equal to the current page index.
You can find a working example in the BottomNavigationBar api page: https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html#material.BottomNavigationBar.3
The best and most easiest way to do this without any scroll controller or anything would be to use the
AutomaticKeepAliveClientMixin
AutomaticKeepAliveClientMixin Docs
Another question on stack overflow:
SO link