版本 : flutter_screenutil: ^2.2.0
一个用于调整屏幕和字体大小的flutter插件。让您的UI在不同的屏幕大小上显示合理的布局!
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 | import 'package:flutter_screenutil/flutter_screenutil.dart'; /// 直接通过`类名称`访问里面的方法,方法为 静态方法 class ScreenAdaper { static init(context){ /// 设计稿 --- 宽/高 ScreenUtil.init(); ScreenUtil.init(width: 750, height: 1334); ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2 } static sp(double value){ return ScreenUtil().setSp(value, allowFontScalingSelf: true); /// 获取 计算后的字体 } static height(double value){ return ScreenUtil().setHeight(value); /// 获取 计算后的高度 } static width(double value){ return ScreenUtil().setWidth(value); /// 获取 计算后的宽度 } static screenHeight(){ return ScreenUtil.screenHeight; /// 获取 计算后的屏幕高度 } static screenWidth(){ return ScreenUtil.screenWidth; /// 获取 计算后的屏幕高度 } } |