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

标签 flutter flutter-layout

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

关于Flutter - 如何在 ListView 中居中小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52991376/

相关文章:

Flutter StreamProvider 使用了一个 `BuildContext`,它是提供者的祖先

dart - 调用构造函数 super 错误,传递了 3 个,预期为 0 个

flutter - 如何保存自定义绘画中的图像?

flutter - 将可拖动标记添加到 flutter 应用程序 Mapbox

flutter - 向DropDownButton添加单独的值

android - Flutter Multiline 文本

dart - Flutter Copy & Past Popup 从视口(viewport)溢出

flutter - 将列表转换为 Json 字符串,然后将此字符串转换回 Dart 中的列表

flutter - 在底部抽屉导航 flutter 中注销

Flutter - TabBarView 内部的 ListView 失去滚动位置