I'm trying to create chat bubbles and have them wrap around the text without expanding to the other end of the screen. I've seen the other threads on how to do this and have tried implementing it but none of it works. Here are the threads I've seen and tried implementing the suggested fixes:
Wrap text in container without using a fixed width in Flutter
Currently this is what happens when I have a background in my container:
My code:
Widget build(BuildContext context) {
return new SizeTransition(
sizeFactor: new CurvedAnimation(
parent: animationController.view,
curve: Curves.easeOut),
axisAlignment: 0.0,
child: new Container(
decoration: BoxDecoration(
border: Border.all(
color: (text[0]=='r') ? lightVioletBlue :mintgreen,
width: 2.0,
style: BorderStyle.solid,
),
borderRadius: BorderRadius.all(Radius.circular(20)),
color: (text[0] == 'r') ? lightVioletBlue:mintgreen,
),
margin: const EdgeInsets.symmetric(vertical: 10.0),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Container(
margin: const EdgeInsets.only(right: 16.0),
child: (text[0] == 'r') //If first letter is an r, then it indicates it's a reply.
? new CircleAvatar(child: new Text(_otherName[0]))
: null
),
new Expanded(
child: new Column(
crossAxisAlignment: (text[0] == 'r') //If first letter is an r, then it indicates it's a reply.
? CrossAxisAlignment.start
: CrossAxisAlignment.end,
children: <Widget>[
new Text((text[0] == 'r') ? _otherName : _name, //If first letter is an r, then it indicates it's a reply.
style: (text[0] == 'r') ? TextStyle(color: Colors.white) : Theme.of(context).textTheme.subhead),
new Container(
margin: const EdgeInsets.only(top: 5.0),
child: (text[0] == 'r') //If first letter is an r, then it indicates it's a reply.
? new Text(text.substring(1), style: TextStyle(color: Colors.white))
: new Text(text),
),
],
),
),
new Container(
margin: const EdgeInsets.only(left: 16.0),
child: (text[0] == 'r') //If first letter is an r, then it indicates it's a reply.
? null
: new CircleAvatar(child: new Text(_name[0]))),
],
),
) //new
);
}
I've tried adding constraints on the parent container, however that requires me to create a fixed size (at least to my own understanding of flutter) and the container still starts on the left. So the messages from "Ken" would end up on the right side of the container, but the container ends in the middle of the screen.