Flutter-如何在列表视图内将小部件居中
问题内容:
我正在努力将小部件放在内部居中listView
。
我试过了,但Text('ABC')
没有垂直居中。我该如何实现?
new Scaffold(
appBar: new AppBar(),
body: new ListView(
padding: const EdgeInsets.all(20.0),
children: [
new Center(
child: new Text('ABC')
)
]
)
);
问题答案:
垂直居中和水平居中:
Scaffold(
appBar: new AppBar(),
body: Center(
child: new ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(20.0),
children: [
Center(child: new Text('ABC'))
]
),
),
);
仅垂直中心
Scaffold(
appBar: new AppBar(),
body: Center(
child: new ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(20.0),
children: [
new Text('ABC')
]
),
),
);