English 中文(简体)
如何在适应性的罗尔法中有两个灵活项目?
原标题:How to have two Flexible items in a Row flex adaptively?
  • 时间:2024-03-26 00:34:44
  •  标签:
  • flutter

我有一张罗子,内有2个灵活文本。

Row(
  children: [
    Flexible(child: Text( blah )),
    Flexible(child: Text( blah )),
  ],
);

我想说明如何做到:

  • When both items are short, align item 1 to start and item 2 to end.
  • When item 1 is long and wants to take up more width than its flex bound - allow this as long as item 2 is not taking up that space (and vice versa)
  • When both items are long, respect the flex bound and maintain the 1:1 flex ratio.

I ve 尝试了Expand FlexibleMainAxisAlignment等各种组合:,但似乎无法说明如何照搬上述要求。

任何帮助都将受到高度赞赏。

问题回答

If you want the text to automatically adjust its size if it s too long to fit within its container, you can use the overflow property along with maxLines property.you can wrap both Text widgets with Flexible widgets and set their fit properties to FlexFit.tight. Here s how you can modify the code:

    Row(
  children: [
    Flexible(
      fit: FlexFit.tight,
      child: Text(
         blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah ,
        overflow: TextOverflow.ellipsis,
        maxLines: 1, // Adjust as needed
      ),
    ),
    Flexible(
      fit: FlexFit.tight,
      child: Text( blah ),
    ),
  ],
);




相关问题
Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...