responsive.dart 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import 'package:flutter/material.dart';
  2. class ResponsiveBreakpoints {
  3. static const double phone = 700;
  4. static const double tablet = 900;
  5. static const double sidebarWidth = 288;
  6. static bool isPhone(BuildContext context) =>
  7. MediaQuery.of(context).size.width < phone;
  8. static bool isTablet(BuildContext context) =>
  9. MediaQuery.of(context).size.width >= phone &&
  10. MediaQuery.of(context).size.width < tablet;
  11. static bool isDesktop(BuildContext context) =>
  12. MediaQuery.of(context).size.width >= tablet;
  13. static bool showPersistentSidebar(BuildContext context) =>
  14. MediaQuery.of(context).size.width >= phone;
  15. static EdgeInsets padding(BuildContext context) {
  16. final w = MediaQuery.of(context).size.width;
  17. if (w >= tablet) return const EdgeInsets.all(24);
  18. if (w >= phone) return const EdgeInsets.all(16);
  19. return const EdgeInsets.all(12);
  20. }
  21. static double contentMaxWidth(BuildContext context) {
  22. final w = MediaQuery.of(context).size.width;
  23. if (w >= tablet) return w * 0.7;
  24. return w;
  25. }
  26. }