showModalBottomSheet的Flutter onClosing回调 [英] Flutter onClosing callback for showModalBottomSheet

查看:1187
本文介绍了showModalBottomSheet的Flutter onClosing回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 showModalBottomSheet ,如下所示,我知道它是从 BottomSheet 继承的(对吗?)

I have a showModalBottomSheet like the below, which I understand to inherit from BottomSheet (right?)

      showModalBottomSheet<void>(
        context: context,
        builder: (BuildContext context) {
          return Container(
            height: 260.0,
            child: Text('I am text')
          );
        },
      );

我想做什么:

我想知道(监听)何时关闭模式,并对其执行操作。

I want to know (listen) when the modal is being closed, and act on it.

我在关闭时看到了此 回调:
https://docs.flutter.io/ flutter / material / BottomSheet / onClosing.html

I've seen this onClosing callback: https://docs.flutter.io/flutter/material/BottomSheet/onClosing.html

如何将监听器附加到 showModalBottomSheet

How can I have a listener attached to the showModalBottomSheet, and then act accordingly when it fires?

推荐答案

也许不是最佳解决方案,但是showModalBottomSheet返回 Future您可以使用它。

Perhaps it's not the best solution, but showModalBottomSheet return a "Future" so you can used it.

例如:

void _showModal() {
    Future<void> future = showModalBottomSheet<void>(
      context: context,
      builder: (BuildContext context) {
        return Container(height: 260.0, child: Text('I am text'));
      },
    );
    future.then((void value) => _closeModal(value));
}
void _closeModal(void value) {
    print('modal closed');
}

这篇关于showModalBottomSheet的Flutter onClosing回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆