firebase 向聊天消息添加时间抖动

svmlkihl  于 2022-11-17  发布在  其他
关注(0)|答案(1)|浏览(130)

我必须在我的应用程序中创建一个聊天。问题是有人发送消息的时间没有正确地放在聊天屏幕上,数字不正确或不长。时间应该是这样的(13:36)。有人知道我如何像sapp那样把时间放在消息下面吗?这是我的聊天屏幕here

class MessageTile extends StatelessWidget {
  final String message;
  final bool sendByMe;
  final int time;

  MessageTile({@required this.message, @required this.sendByMe, @required this.time});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: sendByMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
      children: <Widget>[
        Text( sendByMe ? time.toString() : time.toString(),style: sendByMe ?
        TextStyle(color: Colors.blue, fontWeight: FontWeight.bold, fontFamily: 'Orbitron', fontSize: 7.0,):
        TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontFamily: 'Orbitron', fontSize: 7.0,) ,
       ),
        Container(
          padding: EdgeInsets.only(
              top: 3,
              bottom: 3,
              left: sendByMe ? 0 : 24,
              right: sendByMe ? 24 : 0),
          alignment: sendByMe ? Alignment.centerRight : Alignment.centerLeft,
          child: Container(
            margin: sendByMe
                ? EdgeInsets.only(left: 30)
                : EdgeInsets.only(right: 30),
            padding: EdgeInsets.only(
                top: 17, bottom: 17, left: 20, right: 20),
            decoration: BoxDecoration(
                borderRadius: sendByMe ? BorderRadius.only(
                    topLeft: Radius.circular(9),
                    topRight: Radius.circular(9),
                    bottomLeft: Radius.circular(9),
                ) :
                BorderRadius.only(
                    topLeft: Radius.circular(9),
                    topRight: Radius.circular(9),
                    bottomRight: Radius.circular(9)),
               color: sendByMe ? Colors.blue : Colors.white
            ),
            child: Text(message,
                    textAlign: TextAlign.start,
                    style: TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                    fontFamily: 'Orbitron',
                    fontSize: 9.0,),),
            ),
        ),
      ],
    );
  }
p4rjhz4m

p4rjhz4m1#

time.toString()替换为DateTime.fromMillisecondsSinceEpoch(time).toString()

child: Text( sendByMe ? DateTime.fromMillisecondsSinceEpoch(time).toString() : DateTime.fromMillisecondsSinceEpoch(time).toString(),style: sendByMe ?
      TextStyle(color: Colors.blue, fontFamily: 'Orbitron', fontSize: 9.0,):
      TextStyle(color: Colors.white, fontFamily: 'Orbitron', fontSize: 9.0,),
      ),

相关问题