Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
flutter_screenutil
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
李卓原
2020-07-16 20:10:44 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
108ef8dedaefb202224da20696ea1e71df4fee59
108ef8de
1 parent
caed30e4
2.3
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
61 additions
and
56 deletions
CHANGELOG.md
README.md
README_CN.md
README_PT.md
example/android/gradle.properties
example/android/gradlew
example/ios/Flutter/flutter_export_environment.sh
example/lib/main.dart
example/lib/main_zh.dart
lib/screenutil.dart
pubspec.yaml
CHANGELOG.md
View file @
108ef8d
...
...
@@ -6,6 +6,9 @@
*
@Description: Update log
-->
# 2.3.0
-
We still need context to initialize, sorry.
# 2.2.0
-
add 'wp','hp'. Get the height/width of the screen proportionally
-
For example: 0.5.wp : Half the width of the screen.
...
...
README.md
View file @
108ef8d
...
...
@@ -49,16 +49,16 @@ Be sure to set the page in the MaterialApp's home/initialRoute(ie the entry file
//fill in the screen size of the device in the design
//default value : width : 1080px , height:1920px , allowFontScaling:false
ScreenUtil
.
init
(
context
);
//flutter_screenuitl < 1.2
ScreenUtil
.
init
();
//flutter_screenuitl >= 1.2
ScreenUtil
.
init
(
context
);
~~
//flutter_screenuitl < 1.2~~
~~
ScreenUtil
.
init
();
//flutter_screenuitl >= 1.2~~
//If the design is based on the size of the iPhone6 (iPhone6 750*1334)
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
);
//flutter_screenuitl < 1.2
ScreenUtil
.
init
(
width:
750
,
height:
1334
);
//flutter_screenuitl >= 1.2
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
);
~~
//flutter_screenuitl < 1.2~~
~~
ScreenUtil
.
init
(
width:
750
,
height:
1334
);
//flutter_screenuitl >= 1.2~~
//If you want to set the font size is scaled according to the system's "font size" assist option
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
true
);
//flutter_screenuitl < 1.2
ScreenUtil
.
init
(
width:
750
,
height:
1334
,
allowFontScaling:
true
);
//flutter_screenuitl >= 1.2
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
true
);
~~
//flutter_screenuitl < 1.2~~
~~
ScreenUtil
.
init
(
width:
750
,
height:
1334
,
allowFontScaling:
true
);
//flutter_screenuitl >= 1.2~~
```
...
...
README_CN.md
View file @
108ef8d
...
...
@@ -53,16 +53,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
//填入设计稿中设备的屏幕尺寸
//默认 width : 1080px , height:1920px , allowFontScaling:false
ScreenUtil.init(context); //flutter_screenuitl < 1.2
ScreenUtil.init(); //flutter_screenuitl >= 1.2
ScreenUtil.init(context); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(); //flutter_screenuitl >= 1.2~~
//假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil.init(context, width: 750, height: 1334); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334); //flutter_screenuitl >= 1.2~~
//设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl < 1.2
ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2
ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true); ~~//flutter_screenuitl < 1.2~~
~~ScreenUtil.init(width: 750, height: 1334, allowFontScaling: true); //flutter_screenuitl >= 1.2~~
```
...
...
README_PT.md
View file @
108ef8d
...
...
@@ -49,16 +49,16 @@ Certifique-se de definir as dimensões na paginal inicial do MaterialApp (ou sej
//Preencha o tamanho da tela do dispositivo no protótipo de design
//Valor padrão: width : 1080px , height:1920px , allowFontScaling:false
ScreenUtil
.
init
(
context
);
//flutter_screenuitl < 1.2
ScreenUtil
.
init
();
//flutter_screenuitl >= 1.2
ScreenUtil
.
init
(
context
);
~~
//flutter_screenuitl < 1.2~~
~~
ScreenUtil
.
init
();
//flutter_screenuitl >= 1.2~~
//Se o design é baseado no iPhone6 (iPhone6 750*1334)
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
);
//flutter_screenuitl < 1.2
ScreenUtil
.
init
(
width:
750
,
height:
1334
);
//flutter_screenuitl >= 1.2
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
);
~~
//flutter_screenuitl < 1.2~~
~~
ScreenUtil
.
init
(
width:
750
,
height:
1334
);
//flutter_screenuitl >= 1.2~~
//Se você quer definir que o tamanho da fonte seja ajustado de acordo com a opção "tamanho da fonte" na acessibilidade do sistema
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
true
);
//flutter_screenuitl < 1.2
ScreenUtil
.
init
(
width:
750
,
height:
1334
,
allowFontScaling:
true
);
//flutter_screenuitl >= 1.2
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
true
);
~~
//flutter_screenuitl < 1.2~~
~~
ScreenUtil
.
init
(
width:
750
,
height:
1334
,
allowFontScaling:
true
);
//flutter_screenuitl >= 1.2~~
```
...
...
example/android/gradle.properties
View file @
108ef8d
org.gradle.jvmargs
=
-Xmx1536M
android.enableR8
=
true
android.useAndroidX
=
true
android.enableJetifier
=
true
\ No newline at end of file
...
...
example/android/gradlew
100644 → 100755
View file @
108ef8d
example/ios/Flutter/flutter_export_environment.sh
100644 → 100755
View file @
108ef8d
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export
"FLUTTER_ROOT=D:
\D
evelop
\f
lutter"
export
"FLUTTER_APPLICATION_PATH=D:
\D
evelop
\P
roject
\f
lutter_screenutil
\e
xample"
export
"FLUTTER_TARGET=lib
\m
ain.dart"
export
"FLUTTER_ROOT=/Users/lizhuoyuan/Development/flutter"
export
"FLUTTER_APPLICATION_PATH=/Users/lizhuoyuan/Development/Project/flutter_screenutil/example"
export
"FLUTTER_TARGET=lib/main.dart"
export
"FLUTTER_BUILD_DIR=build"
export
"SYMROOT=
${
SOURCE_ROOT
}
/../build
\i
os"
export
"OTHER_LDFLAGS=
$(
inherited
)
-framework Flutter"
export
"FLUTTER_FRAMEWORK_DIR=D:
\D
evelop
\f
lutter
\b
in
\c
ache
\a
rtifacts
\e
ngine
\i
os"
export
"SYMROOT=
${
SOURCE_ROOT
}
/../build/ios"
export
"FLUTTER_FRAMEWORK_DIR=/Users/lizhuoyuan/Development/flutter/bin/cache/artifacts/engine/ios"
export
"FLUTTER_BUILD_NAME=1.0.0"
export
"FLUTTER_BUILD_NUMBER=1"
...
...
example/lib/main.dart
View file @
108ef8d
import
'dart:ui'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
...
...
@@ -26,7 +28,7 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget
build
(
BuildContext
context
)
{
//Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 (iPhone6 750*1334)
ScreenUtil
.
init
(
width:
750
,
height:
1334
,
allowFontScaling:
false
);
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
false
);
return
ExampleWidget
(
title:
'FlutterScreenUtil Demo'
);
}
...
...
@@ -44,7 +46,7 @@ class ExampleWidget extends StatefulWidget {
class
_ExampleWidgetState
extends
State
<
ExampleWidget
>
{
@override
Widget
build
(
BuildContext
context
)
{
printScreenInformation
();
//
printScreenInformation();
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
widget
.
title
),
...
...
@@ -123,7 +125,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
floatingActionButton:
FloatingActionButton
(
child:
Icon
(
Icons
.
title
),
onPressed:
()
{
ScreenUtil
.
init
(
width:
1500
,
height:
1334
,
allowFontScaling:
false
);
ScreenUtil
.
init
(
context
,
width:
1500
,
height:
1334
,
allowFontScaling:
false
);
setState
(()
{});
},
),
...
...
example/lib/main_zh.dart
View file @
108ef8d
...
...
@@ -31,7 +31,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget
build
(
BuildContext
context
)
{
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil
.
init
(
width:
750
,
height:
1334
,
allowFontScaling:
false
);
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
false
);
return
ExampleWidget
(
title:
'FlutterScreenUtil示例'
);
}
...
...
@@ -126,7 +126,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
floatingActionButton:
FloatingActionButton
(
child:
Icon
(
Icons
.
title
),
onPressed:
()
{
ScreenUtil
.
init
(
width:
1500
,
height:
1334
,
allowFontScaling:
false
);
ScreenUtil
.
init
(
context
,
width:
1500
,
height:
1334
,
allowFontScaling:
false
);
setState
(()
{});
},
),
...
...
lib/screenutil.dart
View file @
108ef8d
...
...
@@ -3,7 +3,7 @@
* email: zhuoyuan93@gmail.com
*/
import
'
dart:ui
'
;
import
'
package:flutter/material.dart
'
;
class
ScreenUtil
{
static
ScreenUtil
_instance
;
...
...
@@ -19,7 +19,7 @@ class ScreenUtil {
/// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false.
bool
allowFontScaling
;
static
double
_screenWidth
;
static
double
_screenWidth
;
static
double
_screenHeight
;
static
double
_pixelRatio
;
static
double
_statusBarHeight
;
...
...
@@ -32,22 +32,24 @@ class ScreenUtil {
return
_instance
;
}
static
void
init
(
static
void
init
(
BuildContext
context
,
{
num
width
=
defaultWidth
,
num
height
=
defaultHeight
,
bool
allowFontScaling
=
false
})
{
num
height
=
defaultHeight
,
bool
allowFontScaling
=
false
})
{
if
(
_instance
==
null
)
{
_instance
=
ScreenUtil
.
_
();
}
_instance
.
uiWidthPx
=
width
;
_instance
.
uiHeightPx
=
height
;
_instance
.
allowFontScaling
=
allowFontScaling
;
_pixelRatio
=
window
.
devicePixelRatio
;
_screenWidth
=
window
.
physicalSize
.
width
;
_screenHeight
=
window
.
physicalSize
.
height
;
_statusBarHeight
=
window
.
padding
.
top
;
_bottomBarHeight
=
window
.
padding
.
bottom
;
_textScaleFactor
=
window
.
textScaleFactor
;
MediaQueryData
mediaQuery
=
MediaQuery
.
of
(
context
);
_pixelRatio
=
mediaQuery
.
devicePixelRatio
;
_screenWidth
=
mediaQuery
.
size
.
width
;
_screenHeight
=
mediaQuery
.
size
.
height
;
_statusBarHeight
=
mediaQuery
.
padding
.
top
;
_bottomBarHeight
=
mediaQuery
.
padding
.
bottom
;
_textScaleFactor
=
mediaQuery
.
textScaleFactor
;
}
/// 每个逻辑像素的字体像素数,字体的缩放比例
...
...
@@ -60,27 +62,23 @@ class ScreenUtil {
/// 当前设备宽度 dp
/// The horizontal extent of this size.
static
double
get
screenWidth
=>
_screenWidth
/
_pixelRatio
;
static
double
get
screenWidth
=>
_screenWidth
;
///当前设备高度 dp
///The vertical extent of this size. dp
static
double
get
screenHeight
=>
_screenHeight
/
_pixelRatio
;
static
double
get
screenHeight
=>
_screenHeight
;
/// 当前设备宽度 px
/// The vertical extent of this size. px
static
double
get
screenWidthPx
=>
_screenWidth
;
static
double
get
screenWidthPx
=>
_screenWidth
*
_pixelRatio
;
/// 当前设备高度 px
/// The vertical extent of this size. px
static
double
get
screenHeightPx
=>
_screenHeight
;
/// 状态栏高度 dp 刘海屏会更高
/// The offset from the top
static
double
get
statusBarHeight
=>
_statusBarHeight
/
_pixelRatio
;
static
double
get
screenHeightPx
=>
_screenHeight
*
_pixelRatio
;
/// 状态栏高度 dp 刘海屏会更高
/// The offset from the top
static
double
get
statusBarHeight
Px
=>
_statusBarHeight
;
static
double
get
statusBarHeight
=>
_statusBarHeight
;
/// 底部安全区距离 dp
/// The offset from the bottom.
...
...
@@ -88,9 +86,9 @@ class ScreenUtil {
/// 实际的dp与UI设计px的比例
/// The ratio of the actual dp to the design draft px
double
get
scaleWidth
=>
screenWidth
/
uiWidthPx
;
double
get
scaleWidth
=>
_
screenWidth
/
uiWidthPx
;
double
get
scaleHeight
=>
screenHeight
/
uiHeightPx
;
double
get
scaleHeight
=>
_
screenHeight
/
uiHeightPx
;
double
get
scaleText
=>
scaleWidth
;
...
...
@@ -119,9 +117,9 @@ class ScreenUtil {
num
setSp
(
num
fontSize
,
{
bool
allowFontScalingSelf
})
=>
allowFontScalingSelf
==
null
?
(
allowFontScaling
?
(
fontSize
*
scaleText
)
:
((
fontSize
*
scaleText
)
/
_textScaleFactor
))
?
(
fontSize
*
scaleText
)
:
((
fontSize
*
scaleText
)
/
_textScaleFactor
))
:
(
allowFontScalingSelf
?
(
fontSize
*
scaleText
)
:
((
fontSize
*
scaleText
)
/
_textScaleFactor
));
?
(
fontSize
*
scaleText
)
:
((
fontSize
*
scaleText
)
/
_textScaleFactor
));
}
...
...
pubspec.yaml
View file @
108ef8d
name
:
flutter_screenutil
description
:
A flutter plugin for adapting screen and font size.Guaranteed to look good on different models
version
:
2.
2
.0
version
:
2.
3
.0
homepage
:
https://github.com/OpenFlutter/flutter_screenutil
environment
:
...
...
Please
register
or
login
to post a comment