dart ListTile,尾部位于顶部

lpwwtiir  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(112)

我试图弄清楚如何改变ListTile中组件的格式。更具体地说,是尾随和标题位置。第一个图像是如何通常它看起来对我来说(caviat是我可以很容易地删除字幕),第二个是我希望它看起来如何。
这可以实现吗?

代码示例:

return Card(
    child: ExpansionTile(
      leading: ListImage(
        image: "path",
      ),
      title: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            "Name",
            style: const TextStyle(fontWeight: FontWeight.bold),
          ),
          Text("Number")
        ],
      ),
      trailing: Text('12'),
    ),
  );
cngwdvgl

cngwdvgl1#

您可以使用列将尾部括起来:

return Card(
  child: ExpansionTile(
    leading: ListImage(
      image: "path",
    ),
    title: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          "Name",
          style: const TextStyle(fontWeight: FontWeight.bold),
        ),
        Text("Number")
      ],
    ),
    trailing: Column(
      children: [
        Text('12'),
      ],
    ),
  ),
);
i86rm4rw

i86rm4rw2#

我认为你不能直接将ListTile中的尾部小部件移到右上方,因为ListTile有特定的布局结构。我试着弄明白了几次没有得到我想要的结果。相反,我可以通过使用Stack小部件来解决这个问题。
这里有一个例子:

return Card(
  child: Stack(
    children: <Widget>[
      Positioned(
        top: 5,
        right: 5,
        child: Text('12'), // your trailing widget
      ),
      ExpansionTile(
        leading: ListImage(
          image: "path",
        ),
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              "Name",
              style: const TextStyle(fontWeight: FontWeight.bold),
            ),
            Text("Number")
          ],
        ),
        subtitle: Text('data'),
        trailing: SizedBox(), // This will remove the default trailing arrow
      ),
    ],
  ),
)

对我很有效。

相关问题