[英]How to show different layout for landscape and portrait in flutter
Just wanted to know how we can show different layout for landscape and portrait in flutter.只是想知道我们如何在 flutter 中显示横向和纵向的不同布局。 In Native for android we just create
layout
and layout-land
folder and put xml files there and system will automatically detect the appropriate layout for orientation.在 Native for android 中,我们只需创建
layout
和layout-land
文件夹并将 xml 文件放在那里,系统将自动检测适当的布局以进行方向。 Any help on flutter would be appreciated.任何有关颤振的帮助将不胜感激。 Thanks
谢谢
Use official widget like docs says https://flutter.dev/docs/cookbook/design/orientation使用像 docs 这样的官方小部件说https://flutter.dev/docs/cookbook/design/orientation
OrientationBuilder(
builder: (context, orientation) {
return GridView.count(
// Create a grid with 2 columns in portrait mode,
// or 3 columns in landscape mode.
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
);
},
);
Use orientation builder and check inside if the orientation is portrait or landscape.使用方向构建器并检查内部方向是纵向还是横向。 Check the documentation here.
检查此处的文档。
Sample Code:示例代码:
OrientationBuilder(
builder: (context, orientation) {
return GridView.count(
// Create a grid with 2 columns in portrait mode,
// or 3 columns in landscape mode.
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
);
},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.