Advertisement
mycar98765

Untitled

Jan 28th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | Source Code | 0 0
  1. class Responsive extends StatelessWidget {
  2. const Responsive({required this.mobile, required this.tablet, required this.desktop, super.key});
  3.  
  4. final Widget mobile;
  5. final Widget tablet;
  6. final Widget desktop;
  7.  
  8. static bool isMobile(BuildContext context) => MediaQuery.of(context).size.width < 600.0;
  9.  
  10. static bool isTablet(BuildContext context) => MediaQuery.of(context).size.width < 1100.0 && MediaQuery.of(context).size.width >= 600.0;
  11.  
  12. static bool isDesktop(BuildContext context) => MediaQuery.of(context).size.width >= 1100.0;
  13.  
  14. @override
  15. Widget build(BuildContext context) => LayoutBuilder(
  16. builder: (context, constraints) => isDesktop(context)
  17. ? desktop
  18. : isTablet(context)
  19. ? tablet
  20. : mobile,
  21. );
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement