听ModalBottomSheet关闭

时间:2018-10-31 13:35:25

标签: dart flutter

当用户关闭模态底部工作表时如何执行代码块?

showModalBottomSheet(
          context: context,
          builder: (BuildContext context) {
            return new MusicR();
          },
        )

2 个答案:

答案 0 :(得分:2)

您可以将showModalBottomSheet分配到Future中。

将发生的情况是,用户将触发模式表上的close动作,并触发对您的future变量的then回调。

示例:

Future<void> bottomSheetAwaitClose = showModalBottomSheet<void>(
  context: context,
  builder: (BuildContext context) {
    return Container();
  },
);

bottomSheetAwaitClose.then((void value) => print ("Bottom sheet closed"));

答案 1 :(得分:2)

下面的代码在关闭底部工作表后显示“ null”

test() async {
  dynamic x = await showModalBottomSheet(context: context, builder: (context) => Container(height: 200.0, color: Colors.green,) );
  print('$x');
  // some other actions
}