responsive.dart 952 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import 'package:flutter/material.dart';
  2. class Responsive extends StatelessWidget {
  3. final Widget? mobile;
  4. final Widget? tablet;
  5. final Widget? desktop;
  6. const Responsive({
  7. Key? key,
  8. @required this.mobile,
  9. this.tablet,
  10. @required this.desktop}) :super(key: key);
  11. @override
  12. Widget build(BuildContext context) {
  13. final size = MediaQuery.of(context).size;
  14. if (size.width >= 1100 && desktop != null) {
  15. return desktop!;
  16. } else if (size.width >= 850 && tablet != null) {
  17. return tablet!;
  18. } else if (mobile != null) {
  19. return mobile!;
  20. }
  21. return Container();
  22. }
  23. static bool isMobile(BuildContext context) => MediaQuery.of(context).size.width < 850;
  24. static bool isTablet(BuildContext context) => MediaQuery.of(context).size.width < 1100 && MediaQuery.of(context).size.width >= 850;
  25. static bool isDesktop(BuildContext context) => MediaQuery.of(context).size.width >= 1100;
  26. }