123456789101112131415161718192021222324252627282930313233343536373839 |
- import 'package:flutter/material.dart';
- /// Description: 响应式布局,根据屏幕宽度:小于850为手机,大于等于850小于1100为平板,大于等于1100为桌面
- /// Time : 04/30/2023 Sunday
- /// Author : liuyuqi.gov@msn.cn
- class Responsive extends StatelessWidget {
- final Widget mobile;
- final Widget tablet;
- final Widget desktop;
- const Responsive({
- super.key,
- required this.mobile,
- required this.tablet,
- required this.desktop,
- });
- // This size work fine on my design, maybe you need some customization depends on your design
- static bool isMobile(BuildContext context) =>
- MediaQuery.of(context).size.width < 850;
- static bool isTablet(BuildContext context) =>
- MediaQuery.of(context).size.width >= 850 &&
- MediaQuery.of(context).size.width < 1100;
- static bool isDesktop(BuildContext context) =>
- MediaQuery.of(context).size.width >= 1100;
- @override
- Widget build(BuildContext context) {
- return LayoutBuilder(
- builder: (context, constraints) => isDesktop(context)
- ? desktop
- : isTablet(context)
- ? tablet
- : mobile,
- );
- }
- }
|