英文:
Why is row expanded?
问题
以下是您的代码的翻译部分:
我正在尝试设计一个简单的聊天气泡,其中包含发送者的姓名和消息。为什么我的行扩展了呢?
以下是我的代码:
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 0),
child: Align(
alignment: widget.senderid ==
chatState.messages[index].senderid
? Alignment.topLeft: Alignment.topRight,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: widget.senderid == chatState.messages[index].senderid
? Colors.grey.shade200
: Colors.blue[200]),
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
child: Column(
children: [Row(children: [
Text('alex')]),
Text('${chatState.messages[index].text!}')]))));
如果您需要任何进一步的帮助,请告诉我。
英文:
I am trying to design a simple chat bubble with sender's name and message. Why my row is expanded?
HEre is my code:
> Container(
> padding: const EdgeInsets.symmetric(
> horizontal: 10, vertical: 0),
> child: Align(
> alignment: widget.senderid ==
> chatState.messages[index].senderid
> ? Alignment.topLeft: Alignment.topRight,
> child: Container(
> decoration: BoxDecoration(
> borderRadius: BorderRadius.circular(15),
> color: widget.senderid ==chatState.messages[index].senderid
> ? Colors.grey.shade200
> : Colors.blue[200]),
> padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
> child: Column(
> children: [ Row(children: [
> Text('alex')]),
> Text('chatState.messages[index].text!')]))));
答案1
得分: 1
要允许 row
使用最小尺寸,您需要使用 mainAxisSize
,这是 row
的属性。
例如:
Row(
mainAxisSize: MainAxisSize.min, //默认为最大
children: [...]
)
同样的属性也适用于 Column
,如果您想使列使用最小尺寸。
英文:
To allow row
to use minimum size you need to use mainAxisSize
which is property of row.
Eg:
Row(
mainAxisSize: MainAxisSize.min. //default is max
children: [...]
)
Same property is available for Column as well if you want to make column to use minimum size.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论