responsive.dart 904 B

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