我正在try 创建一个可滚动的页面(通过使用ListView)并支持响应(通过使用Flex,当屏幕宽度较小时,它将从行切换到列).它是有效的,但我很好奇为什么它需要设置容器的高度.有谁能帮我解释或给我适当的解决方案吗?
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
bool isScreenWide = MediaQuery.sizeOf(context).width >= 800;
return Scaffold(
body: ListView(
children: [
Container(
height: 400, // need this line to make it works
color: Colors.blue[100],
child: Flex(
direction: isScreenWide ? Axis.horizontal : Axis.vertical,
children: [
Expanded(
child: Container(
padding: const EdgeInsets.all(20),
alignment: Alignment.topLeft,
child: const Text("1")),
),
Expanded(
child: Container(
padding: const EdgeInsets.all(20),
alignment: Alignment.topLeft,
child: const Text("2")),
),
],
),
),
],
));
}
}