防止底部 sheet 由于 navigator.pop 而关闭
prevent bottom sheet from closing because of navigator.pop
我有一个带有一堆图标的主页,main page, when I press them I want to navigate into another page where all the songs are listed, and if I click one of them a bottom sheet appear.song list。
到目前为止一切顺利,但是当我尝试使用 navigator.pop
返回主页时,它首先关闭了我的底部 sheet 如果我再按一次该按钮,它会将我带回主页。
那么,怎样才能避免底部sheet被关闭而返回到主页面呢?
您可以使用 WillPopScope
小部件:
WillPopScope(
onWillPop: () async {
if(isPopAllowed){
return true; // allows pop
}
return false; // prevents pop
}
child: Scaffold(...),
);
我有一个带有一堆图标的主页,main page, when I press them I want to navigate into another page where all the songs are listed, and if I click one of them a bottom sheet appear.song list。
到目前为止一切顺利,但是当我尝试使用 navigator.pop
返回主页时,它首先关闭了我的底部 sheet 如果我再按一次该按钮,它会将我带回主页。
那么,怎样才能避免底部sheet被关闭而返回到主页面呢?
您可以使用 WillPopScope
小部件:
WillPopScope(
onWillPop: () async {
if(isPopAllowed){
return true; // allows pop
}
return false; // prevents pop
}
child: Scaffold(...),
);