Flutter_学习记录_各个屏幕的适配

用flutter的这个库,可以解决:https://pub.dev/packages/flutter_screenutil

使用方法:

  1. pubspec.yaml文件中,添加库,如下图:
  2. main.dart中导入头文件
dart 复制代码
import 'package:flutter_screenutil/flutter_screenutil.dart';
  1. Widget build(BuildContext context)方法中,初始化ScreenUtilInit, 代码如下:
dart 复制代码
class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(750, 1334),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (_, child) {
        return MaterialApp(
        // home: Tabs()
          initialRoute: '/',
          onGenerateRoute: onGenerateRoute,
        );
      },
    );
  }
}
  1. 使用方法说明
dart 复制代码
ScreenUtil().setWidth(540)  (dart sdk>=2.6 : 540.w) //Adapted to screen width
    ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w
    ScreenUtil().radius(200)    (dart sdk>=2.6 : 200.r)    //Adapt according to the smaller of width or height
    ScreenUtil().setSp(24)      (dart sdk>=2.6 : 24.sp) //Adapter font
    12.sm   //return min(12,12.sp)

    ScreenUtil().pixelRatio       //Device pixel density
    ScreenUtil().screenWidth   (dart sdk>=2.6 : 1.sw)    //Device width
    ScreenUtil().screenHeight  (dart sdk>=2.6 : 1.sh)    //Device height
    ScreenUtil().bottomBarHeight  //Bottom safe zone distance, suitable for buttons with full screen
    ScreenUtil().statusBarHeight  //Status bar height , Notch will be higher
    ScreenUtil().textScaleFactor  //System font scaling factor

    ScreenUtil().scaleWidth //The ratio of actual width to UI design
    ScreenUtil().scaleHeight //The ratio of actual height to UI design

    ScreenUtil().orientation  //Screen orientation
    0.2.sw  //0.2 times the screen width
    0.5.sh  //50% of screen height
    20.setVerticalSpacing  // SizedBox(height: 20 * scaleHeight)
    20.horizontalSpace  // SizedBox(height: 20 * scaleWidth)
    const RPadding.all(8)   // Padding.all(8.r) - take advantage of const key word
    EdgeInsets.all(10).w    //EdgeInsets.all(10.w)
    REdgeInsets.all(8)       // EdgeInsets.all(8.r)
    EdgeInsets.only(left:8,right:8).r // EdgeInsets.only(left:8.r,right:8.r).
    BoxConstraints(maxWidth: 100, minHeight: 100).w    //BoxConstraints(maxWidth: 100.w, minHeight: 100.w)
    Radius.circular(16).w          //Radius.circular(16.w)
    BorderRadius.all(Radius.circular(16)).w
  1. 可以看看官方文档的说明,这里不再写了。
相关推荐
民乐团扒谱机9 小时前
实验室安全教育与管理平台学习记录(七)网络安全
学习·安全·web安全
蒙奇D索大10 小时前
【11408学习记录】考研英语长难句精析:三步拆解真题复杂结构,轻松攻克阅读难关!
笔记·学习·考研·改行学it
zd20057210 小时前
AI辅助数据分析和学习了没?
人工智能·学习
洛白白10 小时前
“职场心态与心穷
经验分享·学习·生活·学习方法
_dindong11 小时前
笔试强训:Week-4
数据结构·c++·笔记·学习·算法·哈希算法·散列表
DKPT12 小时前
如何设置JVM参数避开直接内存溢出的坑?
java·开发语言·jvm·笔记·学习
一 乐12 小时前
智慧党建|党务学习|基于SprinBoot+vue的智慧党建学习平台(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·学习
海边夕阳200612 小时前
MVCC核心原理解密:从隐藏字段到版本链的完整解析
经验分享·学习·数据库架构·mvcc
woodykissme13 小时前
日内瓦传动装置?不就是我们叫的间歇结构吗?
学习·机械
YJlio13 小时前
PsSuspend(7.23):无损挂起与恢复指定进程——精准“冻住”故障现场
笔记·学习·安全