zefyr

screens.dart 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ///
  2. /// [Author] Alex (https://github.com/AlexV525)
  3. /// [Date] 2020/8/19 10:29
  4. ///
  5. part of ct_assets_picker;
  6. /// Screens utils with multiple properties access.
  7. /// 获取屏幕各项属性的工具类
  8. class Screens {
  9. const Screens._();
  10. /// Get [MediaQueryData] from [ui.window]
  11. /// 通过 [ui.window] 获取 [MediaQueryData]
  12. static MediaQueryData get mediaQuery => MediaQueryData.fromWindow(ui.window);
  13. /// The number of device pixels for each logical pixel.
  14. /// 设备每个逻辑像素对应的dp比例
  15. static double get scale => mediaQuery.devicePixelRatio;
  16. /// The horizontal extent of this size.
  17. /// 水平范围的大小
  18. static double get width => mediaQuery.size.width;
  19. /// The horizontal pixels of this size.
  20. /// 水平范围的像素值
  21. static int get widthPixels => (width * scale).toInt();
  22. /// The vertical extent of this size.
  23. /// 垂直范围的大小
  24. static double get height => mediaQuery.size.height;
  25. /// The vertical pixels of this size.
  26. /// 垂直范围的像素值
  27. static int get heightPixels => (height * scale).toInt();
  28. /// Top offset in the [ui.window], usually is the notch size.
  29. /// 从 [ui.window] 获取的顶部偏移(间距),通常是刘海的大小。
  30. static double get topSafeHeight => mediaQuery.padding.top;
  31. /// Bottom offset in the [ui.window], usually is the action bar/navigation bar size.
  32. /// 从 [ui.window] 获取的底部偏移(间距),通常是操作条/导航条的大小。
  33. static double get bottomSafeHeight => mediaQuery.padding.bottom;
  34. /// Height exclude top and bottom safe height.
  35. /// 去除顶部和底部安全区域的高度
  36. static double get safeHeight => height - topSafeHeight - bottomSafeHeight;
  37. /// Method to update status bar's style.
  38. /// 更新状态栏样式的方法
  39. static void updateStatusBarStyle(SystemUiOverlayStyle style) {
  40. SystemChrome.setSystemUIOverlayStyle(style);
  41. }
  42. /// Scale factor for the text.
  43. /// 文字缩放的倍数
  44. static double get textScaleFactor => mediaQuery.textScaleFactor;
  45. /// Return a fixed font size according to text scale factor.
  46. /// 根据文字缩放计算出的固定文字大小
  47. static double fixedFontSize(double fontSize) => fontSize / textScaleFactor;
  48. }