flutter 屏幕尺寸适配 字体大小适配,android面试常用算法

这篇博客介绍了如何在Flutter中进行屏幕尺寸适配和字体大小适配,使用了flutter_screenutil库,并提供了相关API的使用示例。同时提到了Android面试中常见的算法问题。
摘要由CSDN通过智能技术生成

width: ScreenUtil().setWidth(375),
height: ScreenUtil().setHeight(200),
),

适配字体:

ScreenUtil().setSp(28) //传入字体大小,根据系统的“字体大小”辅助选项来进行缩放
ScreenUtil().setSp(28,false) //传入字体大小,不会根据系统的“字体大小”辅助选项来进行缩放

for example:
Text(
‘My font size is 28px and will not change with the system.’,
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil().setSp(28, false)
)
),

其他相关api:

ScreenUtil.pixelRatio //设备的像素密度
ScreenUtil.screenWidth //设备宽度
ScreenUtil.screenHeight //设备高度
ScreenUtil.bottomBarHeight //底部安全区距离,适用于全面屏下面有按键的
ScreenUtil.statusBarHeight //状态栏高度 刘海屏会更高 单位px
ScreenUtil.textScaleFactory //系统字体缩放比例

ScreenUtil().scaleWidth // 实际宽度的dp与设计稿px的比例
ScreenUtil().scaleHeight // 实际高度的dp与设计稿px的比例

//导入
import ‘package:flutter_screenutil/flutter_screenutil.dart’;

@override
Widget build(BuildContext context) {
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil.instance = ScreenUtil(width:

750, height: 1334)…init(context);
print(‘设备宽度: S c r e e n U t i l . s c r e e n W i d t h ′ ) ; / / D e v i c e w i d t h p r i n t ( ′ 设 备 高 度 : {ScreenUtil.screenWidth}'); //Device width print('设备高度: ScreenUtil.screenWidth);//Devicewidthprint(:{ScreenUtil.screenHeight}’); //Device height
print(‘设备的像素密度: S c r e e n U t i l . p i x e l R a t i o ′ ) ; / / D e v i c e p i x e l d e n s i t y p r i n t ( ′ 底 部 安 全 区 距 离 : {ScreenUtil.pixelRatio}'); //Device pixel density print( '底部安全区距离: ScreenUtil.pixelRatio);//Devicepixeldensityprint(:{ScreenUtil.bottomBarHeight}’); //Bottom safe zone distance,suitable for buttons with full screen
print(
‘状态栏高度:${ScreenUtil.statusBarHeight}px’); //Status bar height , Notch will be higher Unit px

print(‘实际宽度的dp与设计稿px的比例: S c r e e n U t i l ( ) . s c a l e W i d t h ′ ) ; p r i n t ( ′ 实 际 高 度 的 d p 与 设 计 稿 p x 的 比 例 : {ScreenUtil().scaleWidth}'); print('实际高度的dp与设计稿px的比例: ScreenUtil().scaleWidth);p

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值