import 'package:flutter/material.dart'; import 'package:get/get.dart'; /// note this; /// 1,对于竖屏操作,这里我们只考虑宽适配,相当于操作16:9->4:3; /// 2,不考虑宽按照宽的比例缩放,高按照高的比例所犯(16:9->4:3伸缩严重); /// 3,布局中控件/字体中有固定大小的,统一乘以宽的缩放比例,剩余的用弹性布局填充; /// 4,使用之前,请确保_init()函数已经调用; /// 5,布局应该减少相对布局,使用居中布局,方便UI居中显示,和不同宽的两边留白; /// 6, 水平(宽)适配,每个页面应该支持尽量支持高可以滑动 SafeArea + SingleChildScrollView; /// 7,对于没有使用bottomItemBar的页面,如果页面底部有要交互的UI,请加上SafeArea包裹(适应全面屏幕) /// ///class 表示Screen和与之相关的SafeArea var screen = _Screen(); class _Screen { // 全部走 GetX 实时取值,不缓存,免 context、免 configData 时机问题 double get paddingLeft => Get.mediaQuery.padding.left; double get paddingRight => Get.mediaQuery.padding.right; // 一般为状态栏高度 double get paddingTop => Get.mediaQuery.padding.top; // 一般为底部操作栏高度 double get paddingBottom => Get.mediaQuery.padding.bottom; // 水平安全区域 double get screenWidth => Get.width; // 垂直安全区域 double get screenHeight => Get.height; // 设备像素比例 double get devicePixelRatio => Get.mediaQuery.devicePixelRatio; } extension IntWidget on int { Widget get sizeBoxH { return SizedBox(height: toDouble()); } Widget get sizeBoxW { return SizedBox(width: toDouble()); } Widget get line { return Container( height: toDouble(), color: Colors.white.withValues(alpha: .1), ); } Widget get lineV { return Container( height: toDouble(), width: 0.5, color: Colors.white.withValues(alpha: .1), ); } Widget get sliverLine { return SliverToBoxAdapter( child: Container( margin: EdgeInsets.symmetric(horizontal: 16), height: toDouble(), color: Colors.white.withValues(alpha: .1), ), ); } Widget get sliverSizeBoxH { return SliverToBoxAdapter( child: SizedBox(height: toDouble()), ); } } extension DoubleWidget on double { Widget get sizeBoxH { return SizedBox(height: toDouble()); } Widget get sizeBoxW { return SizedBox(width: toDouble()); } Widget get line { return Container( height: toDouble(), color: Colors.white.withValues(alpha: .1), ); } Widget get sliverLine { return SliverToBoxAdapter( child: Container( margin: EdgeInsets.symmetric(horizontal: 16), height: toDouble(), color: Colors.white.withValues(alpha: .1), ), ); } }