如何获取当前小部件的偏移量

use*_*177 8 dart flutter

每当用户按下屏幕时,我都会尝试绘制一个小部件。目前我通过存储一个小部件列表来做到这一点,当 ontapup 在手势上被触发时,我将添加到一个小部件列表中。

Widget build(BuildContext context) {
Widget draw = new Text("A");
List<Widget> children = new List<Widget>();
return new Scaffold(
  appBar: new AppBar(
    title: const Text('Heading'),
    leading: new Icon(Icons.question_answer),
  ),
  body: new GestureDetector(
    onTapUp: (details) {
      setState(() {
          children.add(new Positioned(
            left: details.globalPosition.dx,
            top: details.globalPosition.dy,
            child: draw,
          ));
         });
    },
    child: new Stack(children: children)
    ...
Run Code Online (Sandbox Code Playgroud)

所以我的代码正在工作,我在单击时绘制小部件,但我的问题是,当添加新的 Positioned() 以堆叠位置时,位置基于不包括 appbar 偏移量的屏幕。有没有办法获得堆栈的初始 x/y 位置?或者有没有办法获得appbars的高度?如何获得小部件的位置或高度/宽度?

use*_*177 5

好的,对于其他有同样问题的人,我需要创建自己的小部件并使用

context.findRenderObject() 
Run Code Online (Sandbox Code Playgroud)

globalToLocal()
Run Code Online (Sandbox Code Playgroud)

在我需要使其成为自己的小部件的一种解决方案中,仅供参考全局到本地不起作用。