flutter 如何使此聊天消息正确排列其属性?

6tqwzwtp  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(188)

这是群聊中聊天消息的单行。我需要它看起来像这样:

(circular area for a small icon)      username
(empty space below icon)              message
(empty space below icon)              timestamp (when message is clicked on)

圆形区域将保存来自assets/profileIcons的一组图像资产中的任何一个。我尝试使用下面的代码模拟圆形区域(临时),但是无论我选择什么颜色,图标都不会显示。我只看到一片白色。此外,用户名没有整齐地与消息字段对齐。我很困惑我希望有一种方法可以用GUI来构建它,因为小部件的级联child s读起来真的很烦人。

return Column(
        children: [
          Row(
            children: [
              Expanded(flex: 5,
                  child: Container(
                    margin: EdgeInsets.all(50.0),
                    decoration: BoxDecoration(
                        color: Colors.red,
                        shape: BoxShape.circle
                    ),
                  )
              ),
              Expanded(flex: 8, child: Text(username)),
              Expanded(flex: 15, child: Text('')),
            ],
          ),
          Row(
            children: [
              SizedBox(width: 20,),
              Container(
                constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width * 0.5),
                padding: EdgeInsets.only(left: 15, top: 15, right: 15, bottom: 15),
                decoration: BoxDecoration(
                  color: Color.fromRGBO(66, 135, 245, 100.0),
                  borderRadius: BorderRadius.circular(30),
                ),
                child: Wrap(
                  children: [
                    Text(text),
                  ],
                ),
              ),
            ],
          ),
        ],
      );
0x6upsns

0x6upsns1#

Heading ##listtile ##leading ##chat ## return Scaffold(

body: Column(
    children: [
      ListTile(
        leading: CircleAvatar(backgroundColor: Colors.red,),
        title: Text("Username1"),
        subtitle: Text("message1"),
      ),
      SizedBox(height: 10),
      ListTile(
        leading: CircleAvatar(backgroundColor: Colors.blue),
        title: Text("Username2"),
        subtitle: Text("message2"),
      ),
    ],
  ),
);

相关问题