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

news/2025/2/23 17:52:34

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

使用方法:

  1. pubspec.yaml文件中,添加库,如下图:
    在这里插入图片描述
  2. main.dart中导入头文件
import 'package:flutter_screenutil/flutter_screenutil.dart';
  1. Widget build(BuildContext context)方法中,初始化ScreenUtilInit, 代码如下:
class _MyAppState extends State<MyApp> {
  
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(750, 1334),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (_, child) {
        return MaterialApp(
        // home: Tabs()
          initialRoute: '/',
          onGenerateRoute: onGenerateRoute,
        );
      },
    );
  }
}
  1. 使用方法说明
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. 可以看看官方文档的说明,这里不再写了。

http://www.niftyadmin.cn/n/5863642.html

相关文章

碳基生物的悲歌-DeepSeek思考实现Linux动态库递归收集工具

这是碳基生命的悲歌&#xff0c;还是地球文明的拐点&#xff1f; 今天因为复杂的Linux so 依赖问题&#xff0c;想写一个递归ldd收集所有依赖的工具。抱着试试看的态度&#xff0c;问了DeepSeek&#xff0c;经过5分钟的思考&#xff0c;给出的脚本一次运行通过&#xff0c;我的…

【STM32 USB】USB CDC类

简介 USB CDC&#xff08;communication device class&#xff09;类是usb2.0标准下的一个子类&#xff0c;定义了通信相关设备的抽象集合。usb2.0标准下定义了很多子类&#xff0c;有音频类&#xff0c;CDC类&#xff0c;HID类&#xff0c;打印&#xff0c;大容量存储类&…

stm32常见的存储器应用

常用 STM32 存储器芯片介绍和应用 STM32 微控制器通常与多种存储器芯片一起工作&#xff0c;以下是几种常见的存储器类型及其应用&#xff1a; 1. 闪存&#xff08;Flash Memory&#xff09; STM32 内部的 闪存 是一种非易失性存储器&#xff0c;广泛用于存储程序代码和常驻…

探索 Peewee:轻量级 Python ORM 简明指南

文章目录 探索 Peewee&#xff1a;轻量级 Python ORM 简明指南主要特点&#xff1a;安装&#xff1a;使用示例&#xff1a;1. 定义模型&#xff1a;2. 初始化数据库&#xff1a;3. 数据操作&#xff08;增、查、改、删&#xff09;&#xff1a;4. 查询构建器&#xff1a;5. 迁移…

Python----PyQt开发(PyQt高级:手搓一个音乐播放器)

一、效果展示 二、设计PyQt界面 本次ui界面设置用到了水平和垂直布局 2.1、设置ui窗口显示大小与位置 self.setWindowTitle(音乐播放器) # 设置窗口标题self.setGeometry(800, 300, 800, 800) # 设置窗口大小和位置 2.2、创建显示歌曲列表控件 # 创建显示歌曲列表的控件 …

uniapp 整合openlayers 编辑图形文件并上传到服务器

引入openlayer依赖 import Map from ol/Map.js // OpenLayers的主要类&#xff0c;用于创建和管理地图 import View from ol/View.js // OpenLayers的视图类&#xff0c;定义地图的视图属性 import TileLayer from ol/layer/Tile.js// OpenLayers的瓦片图层类 import…

verilog中等难度设计实践与ALU设计

Verilog中等难度部分设计实践&#xff08;含ALU算术逻辑单元的设计&#xff09; verilog的中等部分根据Deepseek给出的大纲理应包括时序逻辑verilog设计实践和组合逻辑verilog组合设计实践两个部分。 时序逻辑verilog设计和实践 在 Verilog 中&#xff0c;时序逻辑通常通过 …

计算机考研复试上机07

14、数据结构 1)二叉树 1.常用操作 struct TreeNode{int data;TreeNode *leftChild;TreeNode *rightChild; }; //前序遍历 void PreOrder(TreeNode *root){if(root == NULL) return;visit(root->data);PreOrder(root->leftChild);PreOrder(root->rightChild);ret…