我怎样才能获得height的BottomNavigationBar的Scaffold在颤振?我知道这里有MediaQuery.of(context).size屏幕尺寸。有类似的方法BottomNavigationBar吗?
wow*_*lol 11
Container(
width: MediaQuery.of(context).size.width,
height: kBottomNavigationBarHeight,
child: Scaffold(
backgroundColor: Colors.transparent,
body: null,
bottomNavigationBar: BottomNavigationBar()
)
)
Run Code Online (Sandbox Code Playgroud)
这将创建一个只有底部导航栏小部件有足够空间的脚手架。
kBottomNavigationBarHeight 是一个常量,可以在constants.dart 文件中找到。
要获取小部件的大小,您可以使用keyfield
final key = GlobalKey();
... set key field of widget
double height = key.currentContext.size.height;
Run Code Online (Sandbox Code Playgroud)
如果您想知道具有底部导航栏的主支架的子屏幕之一中底部导航栏的高度,您可以使用 MediaQuery:
final bottomPadding = MediaQuery.of(context).padding.bottom;
Run Code Online (Sandbox Code Playgroud)
除了 SafeArea 之外,MediaQuery 的底部填充还考虑了 BottomNavigationBar 的高度。
更详细:
@override
Widget build(BuildContext context) {
final bottomPadding = MediaQuery.of(context).padding.bottom; // From here you will get only SafeArea padding.
return Scaffold(
body: PageView(
children: const [
// But in build() method of each of these screens you will get
// SafeArea padding with bottomNavigationBar height
// just by calling MediaQuery.of(context).padding.bottom;
FirstScreen(),
SecondScreen(),
ThirdScreen(),
FourthScreen(),
],
),
bottomNavigationBar: MyBottomNavigationBar(),
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1474 次 |
| 最近记录: |