flutter - 有没有办法在设备方向更改时关闭模态底页?
问题描述
我已经尝试过:
@override
void didChangeDependencies() {
super.didChangeDependencies();
Orientation orientation = MediaQuery.of(context).orientation;
(orientation == Orientation.portrait)
? print(orientation)
: Navigator.pop(context);
}
在 _BottomContentState 中,但是当我切换设备的方向时这给了我一个错误。
另外,我希望 ModalBottomSheet 在打开时关闭,否则不采取任何行动
解决方案
您可以使用OrientationBuilder
小部件以编程方式关闭您的模态底页。
OrientationBuilder(
builder: (context, orientation) {
if (orientation == Orientation.landscape) {
// Close your modal
}
}
);
推荐阅读
- python - Python - 在虚拟环境中安装包
- python - 了解序列解包:为什么使用集合会抛出“SyntaxError:无法分配给文字”?
- javascript - 如何使用 JavaScript 更改输入中的特定值
- javascript - 反应上下文不更新
- android - 使用共享首选项保存警报对话框的值
- reactjs - 无法使用 React 呈现 onclick 事件
- c# - 什么时候处理对象?C#
- siddhi - 如何从 http-request (sink) 响应中获取源消息?
- google-app-engine - 如何获取 google appengine 应用程序的当前 cron.yaml?
- c - 有什么方法可以真正“打印”\n?