【问题标题】:FLutter :matching Listtile height to card heightFLutter:将Listtile高度匹配到卡片高度
【发布时间】:2021-04-26 07:02:52
【问题描述】:

我正在尝试将 listtile 高度与卡片的高度匹配,但 listtile 高度非常小。它的默认高度非常小。我想改变它以匹配卡片的高度。请帮助我。 以下是我的代码。

 Container(
                margin: EdgeInsets.only(top: 16),
                child: ListView.builder(
                    itemCount: listitems.length,
                    shrinkWrap: true,
                    physics: ClampingScrollPhysics(),
                    itemBuilder: (context, index) {
                      return Column(children:<Widget>[
                        Container(
                          height: 100,
                          child: Card(
                            semanticContainer: true,
                            clipBehavior: Clip.antiAliasWithSaveLayer,

                            child:ListTile(
                              leading: Image.network('https://images.unsplash.com/photo-1550251592-aee2da85a87e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80'),
                            ),
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(10.0),
                            ),
                            elevation: 5,
                            margin: EdgeInsets.all(10),
                          ),
                        ),
                      ]);
                    }),
              ),

任何帮助将不胜感激

【问题讨论】:

  • ListTile 有一个默认高度。是什么阻止您使用 Columns/Rows 创建自己的 listtile?

标签: flutter dart flutter-layout flutter-dependencies flutter-animation


【解决方案1】:

如果我正确理解了文档,ListTile 只是具有固定高度的行的预自定义组合。我无法弄清楚您要寻找什么最终结果,但我检查了您的代码,

a.使用 Container 而不是 ListTile 来设置行/列组合会对您有所帮助,尽管我单独使用了容器并且它有效。

b.尝试移除父容器(高度:110),放置一个容器作为卡片的子容器。 (您的内容可以放在新容器而不是 listTile 下)。 如果您正在寻找特定的结果,请告诉我,我的回答是无关紧要的。

return Scaffold(
      body: Container(
        margin: EdgeInsets.only(top: 16),
        child: ListView.builder(
            itemCount: listitems.length,
            shrinkWrap: true,
            physics: ClampingScrollPhysics(),
            itemBuilder: (context, index) {
              return Column(children:<Widget>[
                Card(
                  semanticContainer: true,
                  clipBehavior: Clip.antiAliasWithSaveLayer,
                  child:Container(
                    child: Image.network('the image url'),
                  ),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10.0),
                  ),
                  elevation: 5,
                  margin: EdgeInsets.all(10),
                ),
              ]);
            }),
      ),
    );

【讨论】:

  • 非常感谢,我尝试使用带有扩展小部件的行列,结果是这样
  • 我附上了由以下代码生成的照片
猜你喜欢
  • 2021-11-27
  • 2020-08-29
  • 1970-01-01
  • 2019-04-03
  • 2020-12-23
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多