-
Notifications
You must be signed in to change notification settings - Fork 0
/
responsive.dart
41 lines (34 loc) · 1012 Bytes
/
responsive.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'package:flutter/material.dart';
class Responsive extends StatelessWidget {
const Responsive({
Key? key,
required this.mobile,
this.tablet,
required this.desktop,
}) : super(key: key);
final Widget mobile;
final Widget? tablet;
final Widget desktop;
//This isMobile
static bool isMobile(BuildContext context) =>
MediaQuery.of(context).size.width < 850;
// isTablet,
static bool isTablet(BuildContext context) =>
MediaQuery.of(context).size.width < 1100 &&
MediaQuery.of(context).size.width >= 850;
//isDesktop
static bool isDesktop(BuildContext context) =>
MediaQuery.of(context).size.width >= 1100;
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
//if our width is more 1100 than we consider it a desktop
if (size.width >= 1100) {
return desktop;
} else if (size.width >= 850 && tablet != null) {
return tablet!;
} else {
return mobile;
}
}
}