responsive.dart 892 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import 'package:flutter/widgets.dart';
  2. class ResponsiveHelper {
  3. final double width;
  4. final double height;
  5. final bool isLandscape;
  6. final bool isWide;
  7. const ResponsiveHelper({
  8. required this.width,
  9. required this.height,
  10. required this.isLandscape,
  11. required this.isWide,
  12. });
  13. factory ResponsiveHelper.of(BuildContext context) {
  14. final media = MediaQuery.of(context);
  15. final w = media.size.width;
  16. final h = media.size.height;
  17. return ResponsiveHelper(
  18. width: w,
  19. height: h,
  20. isLandscape: w > h,
  21. isWide: w > 600,
  22. );
  23. }
  24. int get gridColumns {
  25. if (width > 900) return 4;
  26. if (isLandscape) return 3;
  27. return 2;
  28. }
  29. double get listMaxWidth => isWide ? 600 : double.infinity;
  30. double get formMaxWidth => isWide ? 800 : double.infinity;
  31. bool get formTwoColumns => isWide;
  32. bool get detailTwoColumns => isWide;
  33. }