We will use a custom class called “Responsive” to handle device responsive of the application. Copy this code into Widgets folder.
For device less than 850px, it recognize the device as mobile, 850 – 1100px is table, and anything larger than 1100px is desktop.
import 'package:flutter/material.dart';
class Responsive extends StatelessWidget {
final Widget mobile;
final Widget tablet;
final Widget desktop;
const Responsive({
Key? key,
required this.mobile,
required this.tablet,
required this.desktop,
}) : super(key: key);
static bool isMobile(BuildContext context) =>
MediaQuery.of(context).size.width < 850;
static bool isTablet(BuildContext context) =>
MediaQuery.of(context).size.width < 1100 &&
MediaQuery.of(context).size.width >= 850;
static bool isDesktop(BuildContext context) =>
MediaQuery.of(context).size.width >= 1100;
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
if (size.width >= 1100) {
return desktop;
} else if (size.width >= 850) {
return tablet;
} else {
return mobile;
}
}
}