flutter - 颤振:如何在聊天消息的右下角对齐时间
问题描述
这是我的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),
),
),
],
),
],
))
解决方案
将您的 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),
),
),
],
),
这将解决您的问题。
推荐阅读
- docker - Jenkins Docker 管道插件是指旧的 JENKINS_HOME
- firebase - 是否有云功能触发数据库更改并向用户订阅“主题”发送通知
- javascript - 如何在单页应用程序中触发 url 更改
- c - fgets() + sscanf() 如何写入大于其大小的数组?
- python - keras imagedatagenerator 不使用部分批处理
- postgresql-9.6 - centos7上如何删除postgresql9.6数据库?
- javascript - 在tomcat上部署spring boot应用程序时成功函数(javascript)的问题
- c# - 如何将扩展方法添加到自定义对象列表以将它们转换为新列表
- php - 本地主机:8000 不工作。它只是无限加载?
- javascript - AJAX POST 请求中的“未定义索引”错误,因为 $_POST 为空