I am building a flutter mobile app. There is a BottomNavigationBar in this page and 2 tabs in it. like this
tab1:
tab2:
in tab1 there is a button
in tab2 there is a SingleChildScrollView(code is following)
I want to when I click the button, the app switch to tab2 and scroll the SingleChildScrollView to bottom.
tab1:
BlockImgButton(key:UniqueKey(),Icons.chat_outlined, _unReadMessageNumber,
onPress: (){
print("chat_outlined clicked!");
setState(() {
//switch to tab2
(_bottomNavigationKey.currentWidget as BottomNavigationBar).onTap!(1);
//controll slide
_scrollController.animateTo(_scrollController.position.maxScrollExtent, duration: Duration(milliseconds: 500), curve: Curves.ease);
});
}),
tab2:
Scrollbar(
controller: _scrollController,
thumbVisibility: true,
child:SingleChildScrollView(
controller: _scrollController,
child:
NavigationRail(
//some contents in here
)
)
)
Now when I click the button in tab1, it can successfully switch to tab2 but can not make the Scrollbar to slide.
The Debug information output:
"SingleChildScrollView" ScrollController not attached to any scroll views.
I guess it is because scrollController can not find and attach to SingleChildScrollView when the current screen is in tab1. but how to solve it.
BTW, I tried
WidgetsBinding.instance.addPostFrameCallback((_) {})
but it doesn't work either.