class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('根据方向更新UI'),
),
body: OrientationBuilder(
/// 构建可依赖于父窗口小部件方向的窗口小部件树(与设备方向MediaQuery.of(context).orientation不同)
builder: (context, orientation) => GridView.count(
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
children: List.generate(
100, (index) => Center(child: Text('Item $index'))),
),
),
);
}
}