【问题标题】:How to change background color of ListTile?如何更改 ListTile 的背景颜色?
【发布时间】:2019-01-07 21:46:50
【问题描述】:

我正在制作设置页面,想要制作类似 iOS 设置(灰色背景和白色瓷砖)。我正在尝试添加 Container 以便可以向 ListTile 添加颜色但总是出错。

有人知道如何在这里添加容器吗?

  body: new SingleChildScrollView(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[

               Column(

                children: <Widget>[

                  ListTile(
                    leading: Icon(
                      Icons.person,
                      color: Colors.grey,
                    ),
                    title: Text("Account"),
                    trailing: Icon(Icons.keyboard_arrow_right),
                  ),

【问题讨论】:

  • 如果我明白了,你想要像 that 这样的东西。所以我不明白如果您想更改磁贴背景或父容器(列)背景。

标签: dart flutter flutter-layout


【解决方案1】:

我用Material 小部件包装ListTile 并设置颜色。这将保留 listTile 的涟漪效应。

例如。

Material(
        color: Colors.grey[300],
              child: ListTile(
                title: Text('Hello')
              )

    );

【讨论】:

    【解决方案2】:

    只需将您的 ListTile 包裹在 Container 中即可

      Container(
            color: Colors.grey[200],
            child: ListTile(
              leading: Icon(
                Icons.person,
                color: Colors.grey,
              ),
              title: Text("Account"),
              trailing: Icon(Icons.keyboard_arrow_right),
            ),
          )
    

    【讨论】:

    • 感谢您的回复!我已经尝试过了,但是可以将所有 ListTiles 包装在 Container 中,所以我不必为每个 ListTile 重复包装?尝试使用子项时给出错误“未定义子项”:[in Container.
    • 两个选项,用颜色将你的列包裹在一个容器中,或者创建一个 StatelessWidget 并在那里写你的项目(容器 -> ListTile)
    猜你喜欢
    • 2019-05-09
    • 2021-05-26
    • 2021-02-15
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2018-02-13
    • 2012-01-02
    相关资源
    最近更新 更多