mirror of
https://github.com/ZhuJHua/moodiary.git
synced 2026-04-05 16:39:01 +08:00
41 lines
1.1 KiB
Dart
41 lines
1.1 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:moodiary/common/values/size.dart';
|
|
|
|
class LayoutUtil {
|
|
//获取设备类型
|
|
static ScreenSize getSize() {
|
|
final deviceWidth = Get.size.shortestSide;
|
|
if (deviceWidth > 900) return ScreenSize.desktop;
|
|
if (deviceWidth > 600) return ScreenSize.tablet;
|
|
if (deviceWidth > 300) return ScreenSize.handset;
|
|
return ScreenSize.watch;
|
|
}
|
|
|
|
//获取方向
|
|
static bool isLandSpace() {
|
|
return Get.size.aspectRatio >= 1.0;
|
|
}
|
|
|
|
static List<DeviceOrientation> getOrientation() {
|
|
return switch (getSize()) {
|
|
//手机只能竖屏
|
|
ScreenSize.handset => [DeviceOrientation.portraitUp],
|
|
ScreenSize.tablet => [
|
|
DeviceOrientation.portraitUp,
|
|
DeviceOrientation.landscapeLeft,
|
|
DeviceOrientation.landscapeRight,
|
|
],
|
|
ScreenSize.watch => [
|
|
DeviceOrientation.portraitUp,
|
|
DeviceOrientation.portraitDown,
|
|
],
|
|
ScreenSize.desktop => [
|
|
DeviceOrientation.portraitUp,
|
|
DeviceOrientation.landscapeLeft,
|
|
DeviceOrientation.landscapeRight,
|
|
],
|
|
};
|
|
}
|
|
}
|