Everything expands to screenwidth inside a Listview. Can I change that?

前端 未结 5 2266
深忆病人
深忆病人 2021-02-13 11:59

I\'m trying to make a design of a chat screen for an app that I\'m making. To make it scrollable I placed all the chat messages inside a listview. But everything I place inside

5条回答
  •  不思量自难忘°
    2021-02-13 12:31

    I know this is a bit late but this may be the easiest solution. I don't know if this is a good practice or not (you may comment below if it is not).

    What I did is I wrapped the message (I mean the widget that contains the message) into a row and added a Spacer() widget at first or in last depending upon whether the message is on right side or on left

    So the code might look something like (The code below is for message on the left side)

    Row(
    children: [
      Card(
        color: Colors.green,
        child: new Padding(
          padding: new EdgeInsets.all(7.0),
          child: new Column(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              new Text('Message'),
              new Text('17:00'),
            ],
          ),
        ), 
      )
      Spacer(),
    ]
    )
    

提交回复
热议问题