如何在颤振中找出方向是人像还是景观
if(portrait){
return ListView.builder()
}else{
return GridView.count()
}发布于 2018-06-12 10:48:09
为了确定屏幕的方向,我们可以使用OrientationBuilder Widget。当方向发生变化时,OrientationBuilder将确定当前的方向并重新构建。
new OrientationBuilder(
builder: (context, orientation) {
return new GridView.count(
// Create a grid with 2 columns in portrait mode, or 3 columns in
// landscape mode.
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
);
},
);您可以在这里找到完整的示例:https://flutter.io/cookbook/design/orientation/
发布于 2018-06-12 10:32:47
您可以使用MediaQuery检查方向:
var isPortrait = MediaQuery.of(context).orientation == Orientation.portrait发布于 2018-06-12 10:58:34
这相当简单
if (MediaQuery.of(context).orientation == Orientation.portrait){
// is portrait
}else{
// is landscape
}https://stackoverflow.com/questions/50815014
复制相似问题