【问题标题】:chat bubble showing overflow on long message in flutter聊天气泡在 flutter 中显示长消息溢出
【发布时间】:2022-11-18 01:21:55
【问题描述】:

我在这里创建一个基本的聊天应用程序

我的聊天气泡在长消息上显示溢出错误,如何用多行显示整条消息

有没有办法让我知道它是多行消息还是单行消息,bcz 我想在多行消息时更改设计,我的意思是长消息...

这是我的代码

class MessageCardWidget extends StatelessWidget {
  final MessageModel msgmodel;
  final bool sendbyme;

  const MessageCardWidget(
      {Key? key, required this.msgmodel, required this.sendbyme})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(bottom: 20, left: 40),
      child: Row(
        mainAxisAlignment:
            sendbyme ? MainAxisAlignment.end : MainAxisAlignment.start,
        children: [
          Container(
            decoration: BoxDecoration(
              boxShadow: const [
                BoxShadow(
                    color: Color.fromRGBO(0, 0, 255, 0.2),
                    offset: Offset(1, 1),
                    spreadRadius: 2,
                    blurRadius: 1)
              ],
              borderRadius: BorderRadius.circular(10),
              color: sendbyme ? Colors.green[100] : Colors.white,
            ),
            padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
            child: Column(
              crossAxisAlignment:
                  sendbyme ? CrossAxisAlignment.end : CrossAxisAlignment.start,
              children: [
                Text(
                  msgmodel.msg.toString(),
                  style: TextStyle(fontSize: 20, color: Colors.black),
                ),
                SizedBox(
                  height: 2,
                ),
                Text(
                  DateFormat('hh-mm').format(msgmodel.createdon!).toString(),
                  style: TextStyle(fontSize: 12, color: Colors.grey),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}

【问题讨论】:

    标签: flutter


    【解决方案1】:

    Expanded包裹Text小部件:

    Expanded(
     child: Text(/*...*/),
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多