Sonnat Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
987 B

1 year ago
  1. import 'package:flutter/material.dart' show MediaQuery, BuildContext;
  2. class Metric {
  3. Metric._();
  4. static double width(BuildContext context) => MediaQuery.of(context).size.width;
  5. static double height(BuildContext context) => MediaQuery.of(context).size.height;
  6. static DeviceWidth getScreenWidth(BuildContext context) {
  7. if (width(context) >= 1440) {
  8. return DeviceWidth.lg;
  9. } else if (width(context) >= 976) {
  10. return DeviceWidth.md;
  11. } else if (width(context) >= 576) {
  12. return DeviceWidth.sm;
  13. } else {
  14. return DeviceWidth.xs;
  15. }
  16. }
  17. static bool isDesktop(BuildContext context) => getScreenWidth(context) == DeviceWidth.lg;
  18. static bool isTablet(BuildContext context) => getScreenWidth(context) == DeviceWidth.md;
  19. static bool isCompact(BuildContext context) => getScreenWidth(context) == DeviceWidth.sm;
  20. static bool isMobile(BuildContext context) => getScreenWidth(context) == DeviceWidth.xs;
  21. }
  22. enum DeviceWidth { xs, sm, md, lg }