獲取屏幕相關(guān)
MediaQueryData mq = MediaQuery.of(context);
// 屏幕密度
pixelRatio = mq.devicePixelRatio;
// 屏幕寬(注意是dp, 轉(zhuǎn)換px 需要 screenWidth * pixelRatio)
screenWidth = mq.size.width;
// 屏幕高(注意是dp)
screenHeight = mq.size.height;
// 頂部狀態(tài)欄, 隨著劉海屏?xí)龈? statusBarHeight = mq padding.top;
// 底部功能欄, 類似于iPhone XR 底部安全區(qū)域
bottomBarHeight = mq.padding.bottom;
AppBar BottomNavigationBar
/// material 系統(tǒng)保存的常量值里面查看
export 'src/material/constants.dart’;
/// AppBar 高度
const double kToolbarHeight = 56.0;
/// BottomNavigationBar 高度
const double kBottomNavigationBarHeight = 56.0;
計算的Widget可放置的安全高度 (dp)
/// 安全內(nèi)容高度(包含 AppBar 和 BottomNavigationBar 高度)
double get safeContentHeight => screenHeight - statusBarHeight - bottomBarHeight;
/// 實(shí)際的安全高度
double get safeHeight => safeContentHeight - kToolbarHeight - kBottomNavigationBarHeight;