【发布时间】:2021-11-07 12:45:54
【问题描述】:
我正在尝试制作一个信使应用程序,但找不到解决方案,
问题: 容器小部件不会扩展文本小部件内的长文本
-Container()
|
--> Text()
我尝试了什么:
我在容器内尝试了灵活的小部件而不是文本小部件,但这不起作用。 Flex 在 Container 中不起作用。
**错误:**
════════ 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
════════════════════════════════════════════════════════════════════════════════
我的代码:
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),
),
),
]);
}
}
代码尝试灵活:(不起作用)
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),
),
),
),
]);
}
}
灵活或展开的结果:
我真正想要的是什么?:
ChatBubble 不应等于屏幕大小。 喜欢下面的图片。
【问题讨论】:
-
灵活和扩展都给出了这个错误:
Incorrect use of ParentDataWidget -
你能告诉我在哪里使用扩展或灵活小部件
-
亲爱的@RavindraS.Patil 我想使用容器()内部的文本()。
-
可以添加更新后的代码吗?
标签: flutter dart flutter-layout