flutter字体不跟随系统_Flutter小技巧总结之flutter 适配宽高,字体

//导入

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('设备宽度:${ScreenUtil.screenWidth}'); //Device width

print('设备高度:${ScreenUtil.screenHeight}'); //Device height

print('设备的像素密度:${ScreenUtil.pixelRatio}'); //Device pixel density

print('底部安全区距离:${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的比例:${ScreenUtil().scaleWidth}');

print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');

print('宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}');

print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}');

print('系统的字体缩放比例:${ScreenUtil.textScaleFactory}');return newScaffold(

appBar:newAppBar(

title:newText(widget.title),

),

body:newCenter(

child: Column(

crossAxisAlignment: CrossAxisAlignment.center,

children:[

Row(

children:[

Container(

width: ScreenUtil().setWidth(375),

height: ScreenUtil().setHeight(200),

color: Colors.red,

child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp',

style: TextStyle(

color: Colors.white,

fontSize: ScreenUtil().setSp(12, false),

),

),

),

Container(

width: ScreenUtil().setWidth(375),

height: ScreenUtil().setHeight(200),

color: Colors.blue,

child: Text('我的宽度:${ScreenUtil().setWidth(375)}dp',

style: TextStyle(

color: Colors.white,

fontSize: ScreenUtil().setSp(12, false),

)),

),

],

),

Text('设备宽度:${ScreenUtil.screenWidth}px'),

Text('设备高度:${ScreenUtil.screenHeight}px'),

Text('设备的像素密度:${ScreenUtil.pixelRatio}'),

Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'),

Text('状态栏高度:${ScreenUtil.statusBarHeight}px'),

Text('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}',

textAlign: TextAlign.center,

),

Text('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}',

textAlign: TextAlign.center,

),

Text('宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil.pixelRatio}',

textAlign: TextAlign.center,

),

Text('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil.pixelRatio}',

textAlign: TextAlign.center,

),

SizedBox(

height: ScreenUtil().setHeight(100),

),

Text('系统的字体缩放比例:${ScreenUtil.textScaleFactory}'),

Column(

crossAxisAlignment: CrossAxisAlignment.start,

children:[

Text('我的文字大小在设计稿上是14px,不会随着系统的文字缩放比例变化',

style: TextStyle(

color: Colors.black,

fontSize: ScreenUtil().setSp(14, false))),

Text('我的文字大小在设计稿上是14px,会随着系统的文字缩放比例变化',

style: TextStyle(

color: Colors.black, fontSize: ScreenUtil().setSp(14))),

],

)

],

),

),

);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值