为什么行扩展?

huangapple go评论58阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月31日 23:40:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定