2024-03-18 15:54:06 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2024-03-18 13:23:58 +08:00
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
/// 屏幕适配类
|
|
|
|
class ScreenAdaper {
|
|
|
|
/// 获取 计算后的字体
|
|
|
|
static double sp(double value) {
|
|
|
|
return ScreenUtil().setSp(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 获取 计算后的高度
|
|
|
|
static double height(double value) {
|
|
|
|
return isLandspace()
|
|
|
|
? ScreenUtil().setWidth(value)
|
|
|
|
: ScreenUtil().setHeight(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 获取 计算后的宽度
|
|
|
|
static double width(double value) {
|
|
|
|
return isLandspace()
|
|
|
|
? ScreenUtil().setHeight(value)
|
|
|
|
: ScreenUtil().setWidth(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 获取 计算后的屏幕高度
|
|
|
|
static double screenHeight({notAdapt = false}) {
|
|
|
|
return (isLandspace() && !notAdapt)
|
|
|
|
? ScreenUtil().screenWidth
|
|
|
|
: ScreenUtil().screenHeight;
|
|
|
|
}
|
|
|
|
|
2024-03-28 17:18:46 +08:00
|
|
|
/// 获取 计算后屏幕最窄距离
|
|
|
|
static double screenShortDistance() {
|
2024-03-18 13:23:58 +08:00
|
|
|
return isLandspace() ? ScreenUtil().screenHeight : ScreenUtil().screenWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 获取 计算后的radius
|
|
|
|
static radius(double value) {
|
|
|
|
return ScreenUtil().radius(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Text 尾部整个单词全部变成省略号的问题
|
|
|
|
static overflowByChar(String? text) {
|
2024-03-31 17:13:29 +08:00
|
|
|
return (text ?? '').replaceAll('', '\u200B');
|
2024-03-18 13:23:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static isLandspace() {
|
2024-03-18 15:54:06 +08:00
|
|
|
return Get.context?.orientation == Orientation.landscape;
|
2024-03-18 13:23:58 +08:00
|
|
|
}
|
2024-03-28 17:18:46 +08:00
|
|
|
|
|
|
|
static isTablet() {
|
|
|
|
return ScreenUtil().screenWidth > 650;
|
|
|
|
}
|
2024-03-18 13:23:58 +08:00
|
|
|
}
|