当页面1从页面2返回时,我使用拦截器https://pub.dartlang.org/packages/back_button_interceptor来执行一个方法。
如果我使用设备后退按钮从第2页返回到第1页,则会执行该方法。
但是,如果我使用appBar上的箭头按钮从第2页返回到第1页,我将无法执行该方法。
后退箭头按钮功能如何默认使用设备的后退按钮?
发布于 2022-01-12 15:19:53
AppBar
中默认的后退按钮是来自material.dart
的BackButton
小部件。您可以手动创建它,并传递您自己的onPressed
来执行您想要的操作:
return Scaffold(
appBar: AppBar(
leading: BackButton(onPressed: _onBackPressed),
title: Text('Title'),
),
body: Container(),
);
如果您没有在AppBar
中指定leading
,那么它将使用执行Navigator.maybePop(context)
的处理程序创建一个BackButton
。
https://stackoverflow.com/questions/54971988
复制相似问题