【问题标题】:Automatically close a Flutter modal bottom sheet when the app is paused应用暂停时自动关闭 Flutter 模态底页
【发布时间】:2021-11-11 06:28:21
【问题描述】:

我正在使用showModalBottomSheet 显示模态材料设计底页。

showModalBottomSheet<void>(
  context: context,
  builder: (BuildContext context) {
  ...

我希望在 Flutter Android 应用暂停时(例如用户点击主页按钮)自动关闭(弹出?)。

我该怎么做?

【问题讨论】:

    标签: android flutter dart bottom-sheet flutter-showmodalbottomsheet


    【解决方案1】:

    检查 WidgetsBindingObserver: https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html。您可以在模态小部件中扩展它,并在应用状态暂停时调用 pop()。

    【讨论】:

      【解决方案2】:

      Code to detect if user pressed home / tab on flutter? 可能是一个可行的解决方案?

      如果您检测到应用生命周期中的暂停更改,您可能可以发送navigator.of(context).pop ?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-20
        • 2021-07-24
        • 1970-01-01
        • 1970-01-01
        • 2020-10-26
        • 1970-01-01
        相关资源
        最近更新 更多