当用户关闭模态底部工作表时如何执行代码块?
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return new MusicR();
},
)
答案 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
}