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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart';
class ScreenAdapter { static void init(BuildContext context) { ScreenUtil.init( context, designSize: _getDesignSize(context), minTextAdapt: true, splitScreenMode: true, ); }
static Size _getDesignSize(BuildContext context) { final orientation = MediaQuery.of(context).orientation; return orientation == Orientation.portrait ? const Size(375, 812) : const Size(812, 375); }
static double width(double width) { return width.w; }
static double height(double height) { return height.h; }
static double fontSize(double fontSize) { return fontSize.sp; }
static double get screenWidth => Get.width;
static double get screenHeight => Get.height;
static double get pixelRatio => Get.pixelRatio;
static bool get isPhone => screenWidth < 600; static bool get isTablet => screenWidth >= 600 && screenWidth < 1024; static bool get isDesktop => screenWidth >= 1024;
static T responsive<T>({ required T phone, T? tablet, T? desktop, }) { if (isDesktop && desktop != null) return desktop; if (isTablet && tablet != null) return tablet; return phone; }
static EdgeInsets padding({ double? all, double? horizontal, double? vertical, double? left, double? right, double? top, double? bottom, }) { return EdgeInsets.only( left: (left ?? horizontal ?? all ?? 0).w, right: (right ?? horizontal ?? all ?? 0).w, top: (top ?? vertical ?? all ?? 0).h, bottom: (bottom ?? vertical ?? all ?? 0).h, ); }
static BorderRadius radius([double radius = 0]) { return BorderRadius.circular(radius.r); }
static void addOrientationListener(VoidCallback callback) { ever(Get.mediaQuery as RxInterface<Object?>, (_) => callback()); }
static Orientation get orientation => Get.mediaQuery.orientation; }
|