允许文本小部件在容器之间溢出

3

我刚开始学习Flutter。我目前正在尝试让一个Text小部件在一行中两个容器之间溢出。

以下是代码:

      Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            color: Colors.green,
            width: 100.273,
            height: 150,
            child: const Text(
              "Test",
              overflow: TextOverflow.visible,
              style: TextStyle(
                color: Colors.black,
                decoration: TextDecoration.none,
              ),
            ),
          ),
          Container(
            color: Colors.white,
            width: 100,
            height: 150,
          ),
        ],
      ),

我尝试使用不同的小部件来培养容器,并尝试了不同的TextOverflow值。Visible和Clip似乎没有起作用。我尝试将Text小部件移到行上,并使其通过两个容器进行裁剪,但也没有成功。
这是当前的布局,我希望绿色容器中的“test”能够裁剪到白色容器中。
[image]

你能否添加一张预期输出的截图? - Niladri Raychaudhuri
@NiladriRaychaudhuri 刚刚添加了它!提前致谢。 - Torres
1个回答

1
如果你的意图是在两个容器之上创建一个文本,你可以尝试使用Stack小部件。
这是代码:
Stack(
    children: [
      Row(
        children: [
          Container(
            color: Colors.green,
            width: 100.273,
            height: 150,
          ),
          Container(
            color: Colors.red,
            width: 100,
            height: 150,
          ),
        ],
      ),
      Text('Hallo, this is just test'),
    ],
  ),

see screenshoot


它起作用了,非常感谢! 还必须在 Stack widget 中添加 "alignment: Alignment.center"。 - Torres
好的兄弟,继续努力工作。 - Novan Noviansyah Pratama

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接