如何在Flutter中找出方向是纵向还是横向
if(portrait){ return ListView.builder() }else{ return GridView.count() }
为了确定屏幕的方向,我们可以使用 OrientationBuilderWidget。OrientationBuilder将确定当前Orientation并在Orientation更改时重建。
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/