# flutter_screenutil **Repository Path**: wei-echo/flutter_screenutil ## Basic Information - **Project Name**: flutter_screenutil - **Description**: flutter_screenutil--支持在宽屏幕显示 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-28 - **Last Updated**: 2025-09-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # flutter_screenutil [](https://pub.dev/packages/flutter_screenutil) [](https://pub.dev/packages/flutter_screenutil/score) [](https://pub.dev/packages/flutter_screenutil/score) [](https://www.codefactor.io/repository/github/openflutter/flutter_screenutil) **flutter 屏幕适配方案,用于调整屏幕和字体大小的flutter插件,让你的UI在不同尺寸的屏幕上都能显示合理的布局!** *注意*:此插件仍处于开发阶段,某些API可能尚不可用。 [README of English](https://github.com/OpenFlutter/flutter_ScreenUtil/blob/master/README.md) [README em Português](https://github.com/OpenFlutter/flutter_screenutil/blob/master/README_PT.md) [github](https://github.com/OpenFlutter/flutter_screenutil) [csdn博客工具介绍](https://blog.csdn.net/u011272795/article/details/82795477) [更新日志](https://github.com/OpenFlutter/flutter_screenutil/blob/master/CHANGELOG.md)
## 使用方法: ### 安装依赖: 安装之前请查看最新版本 新版本如有问题请使用以前的版本 ```yaml dependencies: flutter: sdk: flutter # 添加依赖 flutter_screenutil: ^{latest version} ``` ### 在每个使用的地方导入包: ```dart import 'package:flutter_screenutil/flutter_screenutil.dart'; ``` ### 属性 |属性|类型|默认值|描述| |:---|:---|:---|:---| |designSize|Size|Size(360, 690)|设计稿中设备的尺寸(单位随意,建议dp,但在使用过程中必须保持一致)| | deviceSize | Size | null | 物理设备的大小 | |builder|Widget Function()|Container()|一般返回一个MaterialApp类型的Function()| |orientation|Orientation|portrait|屏幕方向| |splitScreenMode|bool|false|支持分屏尺寸| |minTextAdapt|bool|false|是否根据宽度/高度中的最小值适配文字| |context|BuildContext|null|传入context会更灵敏的根据屏幕变化而改变| | child | Widget | null | builder的一部分,其依赖项属性不使用该库 | | rebuildFactor | Function | *default* | 返回屏幕指标更改时是否重建。 | 注意:builder和child中必须填写至少一项 ### 初始化并设置适配尺寸及字体大小是否根据系统的“字体大小”辅助选项来进行缩放 在使用之前请设置好设计稿的宽度和高度,传入设计稿的宽度和高度(单位随意,但在使用过程中必须保持一致) 一定要进行初始化(只需设置一次),以保证在每次使用之前设置好了适配尺寸: #### 方式一(您必须在app中使用它一次): ```dart void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { //填入设计稿中设备的屏幕尺寸,单位dp return ScreenUtilInit( designSize: const Size(360, 690), minTextAdapt: true, splitScreenMode: true, builder: (context , child) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'First Method', // You can use the library anywhere in the app even in theme theme: ThemeData( primarySwatch: Colors.blue, textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp), ), home: child, ); }, child: const HomePage(title: 'First Method'), ); } } ``` #### 方式二: 你需要一个技巧来支持文字自适应主题 **混合开发使用方式二** 不支持这样做: ```dart MaterialApp( ... //如果你想这样做,你应该选择方式一 theme: ThemeData( textTheme: TextTheme( button: TextStyle(fontSize: 45.sp) ), ), ) ``` 正确的方法应当是这样: ```dart void main() async { // Add this line await ScreenUtil.ensureScreenSize(); runApp(MyApp()); } ... MaterialApp( ... builder: (ctx, child) { ScreenUtil.init(ctx); return Theme( data: ThemeData( primarySwatch: Colors.blue, textTheme: TextTheme(bodyText2: TextStyle(fontSize: 30.sp)), ), child: HomePage(title: 'FlutterScreenUtil Demo'), ); }, ) ``` ```dart class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter_ScreenUtil', theme: ThemeData( primarySwatch: Colors.blue, ), home: HomePage(title: 'FlutterScreenUtil Demo'), ); } } class HomePage extends StatefulWidget { const HomePage({Key key, this.title}) : super(key: key); final String title; @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State