获取当前设备平台
第一种,直接通过Platform类来判断,不需要任何参数,很方便
Platform.isAndroid;
Platform.isFuchsia;
Platform.isIOS;
Platform.isLinux;
Platform.isMacOS;
第二种,通过ThemeData拿到TargetPlatform,然后在判断也可以
final ThemeData theme = Theme.of(context);
TargetPlatform targetPlatform = theme.platform;
switch(targetPlatform){
case TargetPlatform.android:
break;
case TargetPlatform.fuchsia:
// TODO: Handle this case.
break;
case TargetPlatform.iOS:
// TODO: Handle this case.
break;
}
获取屏幕宽高
///屏幕size
static Size screenSize(BuildContext context) {
return MediaQuery.of(context).size;
}
/// 屏幕宽度
static double screenWidth(BuildContext context) {
return MediaQuery.of(context).size.width;
}
/// 屏幕高度
static double screenHeight(BuildContext context) {
return MediaQuery.of(context).size.height;
}
获取状态栏高度
MediaQuery.of(context).padding.top