Flutter - 如何在 ListView 中居中小部件

我正在努力将小部件置于 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')
        ]
    ),
  ),
);

https://stackoverflow.com/questions/52991376/

相关文章:

api - 为 HTTPClient get() 请求设置超时

android - 使用 google dart 语言的原生移动应用程序

http - 在flutter http请求中为所有请求设置默认 header 的最佳方法

dart - 如何在 flutter 中将图像转换为base64图像?

flutter - 找不到路线生成器

dart - Flutter 测试 MissingPluginException

Flutter - 容器上的叠加卡片小部件

dart - Flutter - 无法构建,因为框架已经在构建

flutter - 如何在 Flutter 中获取当前选项卡索引

dart - 输入文本时自动扩展的 Flutter 文本字段,然后在达到特定高度时开始滚动文本