Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 定位文本小部件,使小部件的中心位于父堆栈的特定位置_Flutter_Flutter Layout - Fatal编程技术网

Flutter 定位文本小部件,使小部件的中心位于父堆栈的特定位置

Flutter 定位文本小部件,使小部件的中心位于父堆栈的特定位置,flutter,flutter-layout,Flutter,Flutter Layout,我有一个Stack()小部件,里面有一个子Text()小部件。我需要文本小部件的中心位于[左:137,上:201] 使用Positioned(),我只能定位对象的边。如何定位文本小部件的中心?是否有一种方法可以使用子小部件的宽度/高度来偏移定位() Stack( children: [ ..., Positioned( left: 137, // I want these coordinates to be

我有一个Stack()小部件,里面有一个子Text()小部件。我需要文本小部件的中心位于[左:137,上:201]

使用Positioned(),我只能定位对象的边。如何定位文本小部件的中心?是否有一种方法可以使用子小部件的宽度/高度来偏移定位()

Stack(
        children: [
          ...,
          Positioned(
              left: 137,    // I want these coordinates to be the center
              top: 201,     // but they are the top left corner now
              child: Text("20%")
          )])
用Center()包装Text()小部件似乎没有任何作用


我有一个CustomPainter,它绘制的图形是同一堆栈()的一部分,我可以得到任何绘制点的像素坐标。我想要覆盖文本,并且我想要能够在特定点上居中文本。在这张图片中,我希望“20%”文本居中于绿色/蓝色(x:137,y:201)之间的中间十字上,但我只能用Positioned()设置左上角。我可以制作一个硬编码大小超过文本大小的容器。现在我可以将一个中心小部件作为容器的子部件,将文本小部件放在中心小部件中。首先,我可以使用容器的尺寸+坐标来精确定位文本

Positioned(
    top: y-100,
    left: x-100,
    child: Container(
          width: 200,  // Now I just offset my Positioned() parameters
          height: 200, // by half the width & height as done above
          child: Center(
              child: Text(
            "Hello!"
          ))));

解决了这个问题。我可以制作一个硬编码大小超过文本大小的容器。现在我可以将一个中心小部件作为容器的子部件,将文本小部件放在中心小部件中。首先,我可以使用容器的尺寸+坐标来精确定位文本

Positioned(
    top: y-100,
    left: x-100,
    child: Container(
          width: 200,  // Now I just offset my Positioned() parameters
          height: 200, // by half the width & height as done above
          child: Center(
              child: Text(
            "Hello!"
          ))));

我不希望
文本
小部件位于
堆栈
的中心,我希望
文本
小部件的中心位于某个(x,y)位置。我刚刚测试了用
Center
包装小部件,没有成功。您的问题还不够清楚。。。你能为你的结果和你想要的图片添加一张图片吗?我认为这将使其他人很容易阅读你的问题:)。当然!添加了图片和更全面的描述我不希望
文本
小部件位于
堆栈
的中心,我希望
文本
小部件的中心位于某个(x,y)位置。我刚刚测试了用
Center
包装小部件,没有成功。您的问题还不够清楚。。。你能为你的结果和你想要的图片添加一张图片吗?我认为这将使其他人很容易阅读你的问题:)。当然!增加了图片和更全面的描述