我用WillPopScope
Package 了我的支架,但是我的onWillPop
在ios上不支持向后滑动,它只支持按前导,如何让onWillPop
支持向后滑动?
return WillPopScope(
onWillPop: () async {
print('pop');
Navigator.pop(context, product);
setState(() {
product.is_favorite = isFavorite;
});
return true;
},
child: Scaffold(
2条答案
按热度按时间nbysray51#
当导航到当前页面时,您可以使用CupertinoPageRoute代替常规的MaterialPageRoute。
CupertinoPageRoute,向后滑动手势将由iOS导航堆栈处理,该堆栈将依次调用WillPopScope小工具的onWillPop函数
ss2ws0br2#
答案是创建您自己的自定义小部件
CustomPageRoute
和CustomWillPopScope
并使用它们。当我们导航到一个页面时,在Navigator.push期间,我们使用CustomPageRoute,如下所示:
然后在需要
WillPopScope
的页面上,我们也使用定制的WillPopScope
,在Navigator.pop()
中,我们将数据沿着上下文。在我们完成所有这些步骤之后,
WillPopScope
将工作。