我showModalBottomSheet
用来展示模态材料设计底页。
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
...
我希望当 Flutter Android 应用程序暂停时(例如用户正在点击主页按钮)自动关闭(弹出?)。
我怎样才能做到这一点?
我showModalBottomSheet
用来展示模态材料设计底页。
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
...
我希望当 Flutter Android 应用程序暂停时(例如用户正在点击主页按钮)自动关闭(弹出?)。
我怎样才能做到这一点?
检查 WidgetsBindingObserver: https ://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html 。您可以在模态小部件中扩展它,并在应用程序状态暂停时调用 pop()。
检测用户是否在颤动上按下主页/选项卡的代码?可能是一个可行的解决方案?
如果您检测到应用程序生命周期中的暂停更改,您可能可以进行navigator.of(context).pop
?