美文网首页
flutter 获取组件的宽高

flutter 获取组件的宽高

作者: _悟_空 | 来源:发表于2021-12-03 08:48 被阅读0次

一、为组件设置key

GlobalKey _appbarKey = new GlobalKey();

AppBar(key: _appbarKey ,...)

二、获取组件的宽高

  getSize() {
    RenderBox? renderBox = _appbarKey.currentContext?.findRenderObject() as RenderBox;
    print(renderBox.size.height); // 组件高
    print(renderBox.size.width); // 组件宽
  }

相关文章

网友评论

      本文标题:flutter 获取组件的宽高

      本文链接:https://www.haomeiwen.com/subject/xzdpxrtx.html