【问题标题】:Can you Listen for ShowBottomSheet on Close?你能在关闭时收听 ShowBottomSheet 吗?
【发布时间】:2018-08-18 13:34:57
【问题描述】:

想象如下创建一个底部工作表:

final PersistenBottomSheetController bottomSheetController = showBottomSheet(...);

我如何在关闭该底部表时执行逻辑?

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    这对于 Flutter 小部件来说有点单调:
    bottomSheetController.closed 在关闭底部工作表时返回 Future,这允许这种逻辑:

    bottomSheetController.closed.then((value) {
      // this callback will be executed on close
    });
    

    也可以与 await 一起使用:

    await bottomSheetController.closed;
    // code below this call will get executed upon close
    

    【讨论】:

      【解决方案2】:
      final PersistentBottomSheetController<dynamic> bottomSheetController = scaffoldKey.currentState!.showBottomSheet((context) {
                       return Container();
              });
      await bottomSheetController.closed.then((value) {
      // the code for working on drawer close
      });
      

      【讨论】:

      • 请记住,Stack Overflow 不仅仅是为了解决眼前的问题,而是为了帮助未来的读者找到类似问题的解决方案,这需要了解底层代码。这对于我们社区的初学者和不熟悉语法的成员来说尤其重要。鉴于此,您能否edit 您的答案包括对您正在做什么的解释以及为什么您认为这是最好的方法?
      猜你喜欢
      • 1970-01-01
      • 2022-06-14
      • 2019-09-13
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多