Flutter获取屏幕及设备信息

获取状态栏高度

1
2
3
4
5
import 'dart:ui';

MediaQueryData.fromWindow(window).padding.top

MediaQuery.of(context).padding.top

获取系统默认的AppBar等高度

位于Dart Packages/flutter/src/material/constans.dart

1
2
3
4
5
6
7
8
/// The height of the toolbar component of the [AppBar].
const double kToolbarHeight = 56.0;

/// The height of the bottom navigation bar.
const double kBottomNavigationBarHeight = 56.0;

/// The height of a tab bar containing text.
const double kTextTabBarHeight = 48.0;

获取屏幕宽高

1
MediaQuery.of(context).size //获取屏幕大小

获取设备信息

参考:https://docs.flutter.io/flutter/dart-ui/Window-class.html

1
2
3
4
import dart:ui;

window.devicePixelRatio; //获取设备像素比
window.physicalSize; //获取屏幕尺寸

获取平台信息

参考:https://docs.flutter.io/flutter/package-platform_platform/Platform-class.html

1
2
3
import 'dart:io';

Platform.isAndroid;

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :