SizedBox主要有两种用法。
- 对child里面的widget设置高度和宽度。
- 在页面设置留白。这种用法更加常见。
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget> [
Text(
'You have pushed this button many time'
),
// 用法1, 给Text设置高度
SizedBox(
height: 200,
width: 300,
child: Text(
'test 2222'
),
)
],
),
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget> [
Text(
'You have pushed this button many time'
),
// 用法2, 给页面设置了高度为20的留白。
SizedBox(height: 20),
Text(
'test 2222'
)
],
),
),