简体   繁体   English

在行小部件中对齐文本小部件

[英]Align Text widgets in a row widget

I've got a row with 3 text widgets in it. 我一行中有3个文本小部件。

The middle text entry can span several lines, but the first two will be really small. 中间的文本条目可以跨越几行,但是前两行确实很小。

I'm wanting to have the first widget have the text at the top of the row and the 3rd widget to have the text at the bottom of the row. 我想要第一个窗口小部件的文本位于行的顶部,而第三个窗口小部件的文本位于行的底部。

It's basically something similar to this image 基本上与此图片相似

在此处输入图片说明

So basically the first widget would be the opening quote, then the 3rd the ending quote. 因此,基本上第一个窗口小部件将是开头引号,然后是第三个结束号。

I can set a crossAxisAlignment on the row to start or end and that will move the quotes, but it'll move both of them. 我可以在行的开始或结束处设置一个crossAxisAlignment,这将移动引号,但是它将移动两个引号。

At the moment I've got something like this: 目前,我有这样的事情:

return Row(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
      Container(
        padding: const EdgeInsets.symmetric(horizontal: 10.0),
        child: Text('"'),
      ),
      Expanded(
        child: Text(
          entry.text,
          style: style,
        ),
      ),
      Container(
        padding: const EdgeInsets.symmetric(horizontal: 10.0),
        color: Colors.yellow,
        child: Text(
          '”',
          textAlign: TextAlign.start,
        ),
      ),
    ],
  );

but I'm not sure how to align the bottom quote to the bottom of the text, at the moment it sits at the top. 但是我不确定如何将底部引号与文本的底部对齐(目前位于顶部)。

IntrinsicHeight is the widget you are looking for. IntrinsicHeight是您要寻找的小部件。 It's working fine with that widget. 该小部件运行正常。

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: new IntrinsicHeight(
        child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          new Align(
            alignment: Alignment.topLeft,
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 10.0),
              child: Text('"'),
            ),
          ),
          Expanded(
            child: Text(
              "The middle text entry can span several lines, but the first two will be really small. I'm wanting to have the first widget have the text at the top of the row and the 3rd widget to have the text at the bottom of the row. It's basically something similar to this image"
            ),
          ),
          new Align(
            alignment: Alignment.bottomRight,
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 10.0),
              child: Text(
                '”',
                textAlign: TextAlign.start,
              ),
            ),
          ),
        ],
        ),
      ));
  }

one idea would be to create a Stack, than wrap the Text() with Positioned widget. 一种想法是创建一个堆栈,而不是将Text()Positioned小部件包装在一起。 position left quote to top: and left: and right quote to bottom: right: . 位置左引号到top:left:右引号bottom: right: and wrap middle text with Container , calculate the remaining size from MediaQuery.of(context).size.width - qouoteWidth*2 and set fixed size to container and position it at calculated coordinates. 并用Container包裹中间文本,然后从MediaQuery.of(context).size.width - qouoteWidth*2计算剩余大小, MediaQuery.of(context).size.width - qouoteWidth*2容器设置为固定大小并将其放置在计算出的坐标处。

I am sure there are other solutions as well 我相信还有其他解决方案

You can always do Column -> [Expanded(text), Expanded(Container(), Expanded(text)] and adjust the flex of the blank box as needed. 您始终可以执行Column-> [Expanded(text),Expanded(Container(),Expanded(text)]]并根据需要调整空白框的弯曲度。

There's also Container (or Column/Row) -> Stack -> [Column(mainAxis start), Column(mainAxis end)]. 还有容器(或列/行)->堆栈-> [Column(主轴开始),Column(主轴结束)]。

Work smarter, not harder. 更聪明地工作,而不是更努力。 IntrinsicHeight widget is computationally expensive and I would not recommend using it for this. IntrinsicHeight小部件在计算上很昂贵,我不建议为此使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM