【问题标题】:Can I add a badge to a Flutter ListTile that is not the leading or trailing widget?我可以将徽章添加到不是前导或尾随小部件的 Flutter ListTile 吗?
【发布时间】:2021-02-22 22:39:24
【问题描述】:

我的 Flutter 应用中有一个使用 ListView.builder 的列表,类似于上图。我可以添加前导小部件和尾随小部件。

我想要做的是添加一个额外的徽章,例如图片中的那些。 ListTiles 有可能吗?或者有其他方法吗?

【问题讨论】:

    标签: flutter listview


    【解决方案1】:

    请修改此代码。

    ListTile(
                   leading: Icon(Icons.add),
                   title: Text('John judah',),
                   trailing: Row(children: [
                   Icon(Icons.star),
                   Icon(Icons.right),
                    ],),
                ),
    

    【讨论】:

    • 它似乎不起作用 - 我得到这个 'tileWidth != trailingSize.width'。我认为这会使瓷砖太宽,知道如何防止这种情况发生吗?
    • 它作为一个列工作,所以如果我不能使用行,我将使用列
    • 因此,您也可以将两个项目都包装在 Wrap 小部件中,而不是 Row。 @MrHarvey
    【解决方案2】:

    您可以根据需要使用Row 将 2 个小部件并排放置。这将进入 ListTile 中的trailing 参数。

    如果这能解决您的问题,请告诉我!

    【讨论】:

    • 谢谢,和 Muhammad 的回答一样,给他的错误留下了评论
    【解决方案3】:

    试试这个

    ListTile(
      leading: Icon(Icons.notifications),
      title: Text('Notification'),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(Icons.star),
          Icon(Icons.keyboard_arrow_right),
        ],
      ),
    )
    

    【讨论】:

      【解决方案4】:

      Muhammad Tameem Rafay's comment 是正确答案。您可以像这样使用Wrap() 小部件:

      ListTile(
        leading: Icon(Icons.add),
        title: Text('John judah',),
        trailing: Wrap(children: [
          Icon(Icons.star),
          Icon(Icons.right),
        ]),
      ),
      

      【讨论】:

        猜你喜欢
        • 2023-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-05
        • 2012-03-06
        • 1970-01-01
        相关资源
        最近更新 更多