首页 > 解决方案 > 颤振:如何在聊天消息的右下角对齐时间

问题描述

这是我的chat screen截图。我想time不是从一开始就在聊天消息下对齐,而是在聊天磁贴的右下角对齐。

在此处输入图像描述

我怎样才能在我的代码中做到这一点?

 Column(
    crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Container(
                    child: Padding(
                      padding: const EdgeInsets.only(top: 2.0),
                      child: Image.network(senderPhoto,
            ))),
                  SizedBox(width: 20),
                  Text(peerName),
                ],
              ),
              Container(
                  margin: EdgeInsets.only(right: 130),
                  padding: EdgeInsets.only(
                      top: 10, bottom: 10, left: 10, right: 10),
                  ),
                  child: Text(message,
                          textAlign: TextAlign.start,
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 16,
                              )),
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Padding(
                    padding: const EdgeInsets.only(top: 1.0),
                    child: Text(
                      timeSent.toDate(),
                      style: TextStyle(fontSize: 10, color: Colors.white),
                    ),
                  ),
                ],
              ),
            ],
          ))

标签: flutteralignmentchat

解决方案


将您的 timeSent.toDate 填充小部件包装成一行,并给它一个结束的 mainaxisAlignment,如下所示:

     Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Padding(
            padding: const EdgeInsets.only(top: 1.0),
            child: Text(
              timeSent.toDate(),
              style: TextStyle(fontSize: 10, color: Colors.white),
            ),
          ),
        ],
      ),

这将解决您的问题。


推荐阅读