【问题标题】:CircleAvatar in trailing in ListTile not centeredCircleAvatar 在 ListTile 中尾随未居中
【发布时间】:2023-01-17 21:37:32
【问题描述】:

我似乎无法弄清楚如何将我的 CircleAvatar 居中放置在我的 ListTile 的尾部组件中。这是我的代码:

static Widget buildRecordCard(MyCard card, BuildContext context) {
    var dateFormat = DateFormat('MM/dd/yyyy');
    return Column(
      children: [
        ListTile(
            shape:
                RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
            tileColor: Colors.white,
            title: Text(
              "Score: " + card.score!,
              style: const TextStyle(fontSize: 38),
            ),
            subtitle: Column(children: [
              const Align(
                alignment: Alignment.centerLeft,
                child: Text(
                  "Personal Record",
                  style: TextStyle(fontSize: 22),
                ),
              ),
              const SizedBox(height: 6),
              Align(
                alignment: Alignment.centerLeft,
                child: Text(
                  dateFormat.format(card.createdOn.toDate()),
                  style: const TextStyle(fontSize: 18),
                ),
              ),
              const SizedBox(height: 6),
            ]),
            trailing: Container(
              constraints: const BoxConstraints(minWidth: 70.0, maxWidth: 80),
              height: double.infinity,
              child: CircleAvatar(
                  radius: 35,
                  backgroundColor: Colors.transparent,
                  child: Image.asset("assets/" + card.subCategory + ".png")),
            )),
        const SizedBox(height: 18),
      ],
    );
  }

这是它当前输出的内容:

我还尝试将我的 CircleAvatar 包裹在一个 SizedBox 和一个带有 mainAxisAlignment: MainAxisAlignment.center 的 Column 中,它产生了相同的输出。

【问题讨论】:

    标签: flutter containers center listtile


    【解决方案1】:

    在容器上使用 alignment: Alignment.center,

    trailing: Container(
      constraints: const BoxConstraints(minWidth: 70.0, maxWidth: 80),
      height: double.infinity,
      alignment: Alignment.center,
      child: CircleAvatar(
        radius: 35,
        backgroundColor: Colors.transparent,
        child: Image.asset("assets/" + card.subCategory + ".png"),
      ),
    )
    

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 2022-11-24
      • 2020-10-25
      • 2019-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      相关资源
      最近更新 更多