screen.dart 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'dart:ui' as ui show window;
  4. class Screen {
  5. static double get width {
  6. MediaQueryData mediaQuery = MediaQueryData.fromView(ui.window);
  7. return mediaQuery.size.width;
  8. }
  9. static double get height {
  10. MediaQueryData mediaQuery = MediaQueryData.fromView(ui.window);
  11. return mediaQuery.size.height;
  12. }
  13. static double get scale {
  14. MediaQueryData mediaQuery = MediaQueryData.fromView(ui.window);
  15. return mediaQuery.devicePixelRatio;
  16. }
  17. static double get textScaleFactor {
  18. MediaQueryData mediaQuery = MediaQueryData.fromView(ui.window);
  19. return mediaQuery.textScaleFactor;
  20. }
  21. static double get navigationBarHeight {
  22. MediaQueryData mediaQuery = MediaQueryData.fromView(ui.window);
  23. return mediaQuery.padding.top + kToolbarHeight;
  24. }
  25. static double get topSafeHeight {
  26. MediaQueryData mediaQuery = MediaQueryData.fromView(ui.window);
  27. return mediaQuery.padding.top;
  28. }
  29. static double get bottomSafeHeight {
  30. MediaQueryData mediaQuery = MediaQueryData.fromView(ui.window);
  31. return mediaQuery.padding.bottom;
  32. }
  33. static updateStatusBarStyle(SystemUiOverlayStyle style) {
  34. SystemChrome.setSystemUIOverlayStyle(style);
  35. }
  36. }