I am trying to make a messenger app but couldn't find solution for this,
Issue: The container Widget doesn't expand for long text inside Text Widget
-Container()
|
--> Text()
What I Tried:
I Tried Flexible Widget inside container over the Text Widget but that doesn't work. Flex doesn't work inside Container.
**Error : **
════════ Exception caught by rendering library ═════════════════════════════════
A RenderFlex overflowed by 38 pixels on the right.
The relevant error-causing widget was
Row
lib\views\chatScreen.dart:201
════════════════════════════════════════════════════════════════════════════════
My Code :
class MessageBubble extends StatelessWidget {
bool isMine;
String message;
MessageBubble(this.isMine, this.message);
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment:
isMine ? MainAxisAlignment.end : MainAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(7),
decoration: BoxDecoration(
color: isMine ? Colors.blue : Colors.red,
),
child:
child: Text(
message,
textWidthBasis: TextWidthBasis.parent,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
fontSize: 16.0),
),
),
]);
}
}
Code Tried With Flexible: (Doesn't Work)
class MessageBubble extends StatelessWidget {
bool isMine;
String message;
MessageBubble(this.isMine, this.message);
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment:
isMine ? MainAxisAlignment.end : MainAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(7),
decoration: BoxDecoration(
color: isMine ? Colors.blue : Colors.red,
),
child: Flexible(
child: Text(
message,
textWidthBasis: TextWidthBasis.parent,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
fontSize: 16.0),
),
),
),
]);
}
}
Result with Flexible or Expanded:
What I really want?:
The ChatBubble should not be equal to size of the screen. Like the Image Below.