Flutter

Flutter 获取组件高度,状态栏高度,AppBar高度

2022-04-07  本文已影响0人  xxxixxxx

获取组件高度 AppBar 高度

方法一 以 AppBar 为例

Widget build(BuildContext context) {
   // 将 AppBar 定义为变量
  var appBar = AppBar(
    title: const Text('XXX'),
  );
  // 获取高度
  print(appBar.preferredSize.height);
  return Scaffold(appBar: appBar, 
  body: Container());
}

方法二 使用 GlobalKey

final GlobalKey globalKey = GlobalKey();

Stack(
  key: globalKey,
  ....
)

globalKey.currentContext?.size

获取状态栏高度

MediaQuery.of(context).padding.top
上一篇 下一篇

猜你喜欢

热点阅读