1. 插件必须渲染好,

final RenderBox box = globalKey.currentContext.findRenderObject();
final size = box.size;
final topLeftPosition = box.localToGlobal(Offset.zero);
return topLeftPosition.dy;

  

2. 可以通过context.size获取当前控件的尺寸和位置offset信息

下面是示例,通过contex.size.height可以拿到child控件的高度

 

class HeightReporter extends StatelessWidget {
  final Widget child;

  HeightReporter({this.child});

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      child: child,
      onTap: () {
        print('Height is ${context.size.height}');
      },
    );
  }

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-07-03
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2021-07-12
  • 2021-09-12
  • 2021-07-30
  • 2021-10-02
相关资源
相似解决方案