55 lines
1.5 KiB
Dart
55 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class Responsive {
|
|
static bool isMobile(BuildContext context) =>
|
|
MediaQuery.of(context).size.width < 600;
|
|
|
|
static bool isTablet(BuildContext context) =>
|
|
MediaQuery.of(context).size.width >= 600 &&
|
|
MediaQuery.of(context).size.width < 1200;
|
|
|
|
static bool isDesktop(BuildContext context) =>
|
|
MediaQuery.of(context).size.width >= 1200;
|
|
|
|
static double getWidth(BuildContext context) =>
|
|
MediaQuery.of(context).size.width;
|
|
|
|
static double getHeight(BuildContext context) =>
|
|
MediaQuery.of(context).size.height;
|
|
|
|
static double getScaledWidth(BuildContext context, double percentage) =>
|
|
getWidth(context) * (percentage / 100);
|
|
|
|
static double getScaledHeight(BuildContext context, double percentage) =>
|
|
getHeight(context) * (percentage / 100);
|
|
|
|
static EdgeInsets getPadding(BuildContext context) {
|
|
if (isMobile(context)) {
|
|
return const EdgeInsets.all(16.0);
|
|
} else if (isTablet(context)) {
|
|
return const EdgeInsets.all(24.0);
|
|
} else {
|
|
return const EdgeInsets.all(32.0);
|
|
}
|
|
}
|
|
|
|
static double getFontSize(BuildContext context, double baseSize) {
|
|
if (isMobile(context)) {
|
|
return baseSize;
|
|
} else if (isTablet(context)) {
|
|
return baseSize * 1.2;
|
|
} else {
|
|
return baseSize * 1.4;
|
|
}
|
|
}
|
|
|
|
static double getIconSize(BuildContext context, double baseSize) {
|
|
if (isMobile(context)) {
|
|
return baseSize;
|
|
} else if (isTablet(context)) {
|
|
return baseSize * 1.2;
|
|
} else {
|
|
return baseSize * 1.4;
|
|
}
|
|
}
|
|
} |