How to detect orientation change in layout in Flutter?

后端 未结 6 1406
天命终不由人
天命终不由人 2020-12-09 07:56

How to find out Orientation is portrait or landscape in Flutter

if(portrait){
  return ListView.builder()
}else{
  return GridView.count()
}
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 08:22

    OrientationBuilder(
    
    
     builder: (context, orientation) {
          return orientation == Orientation.portrait
              ? SafeArea(
              child: Scaffold(
                  body: PortraitMode(context)
              )
          )
              : LandscapeMode(context);
    
        }
    );
    

提交回复
热议问题