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
LiZhuoyuan
2020-07-23 22:52:14 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f4d9763ca4bda5ab8c4d7b6a2b7e6bf3dd6c21fb
f4d9763c
1 parent
fb1dcfbb
尝试添加个预设字体
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
24 deletions
example/lib/main.dart
example/lib/main_zh.dart
example/lib/text_style.dart
lib/screenutil.dart
example/lib/main.dart
View file @
f4d9763
import
'dart:ui'
;
import
'package:example/text_style.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
...
...
@@ -107,10 +108,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
)),
Text
(
'My font size is 24px on the design draft and will change with the system.'
,
style:
TextStyle
(
color:
Colors
.
black
,
fontSize:
ScreenUtil
()
.
setSp
(
24
,
allowFontScalingSelf:
true
))),
style:
ts
.
t1
),
],
)
],
...
...
example/lib/main_zh.dart
View file @
f4d9763
import
'package:example/text_style.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
...
...
@@ -31,7 +32,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget
build
(
BuildContext
context
)
{
//设置适配尺寸 (填入设计稿中设备的屏幕尺寸) 此处假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
false
);
ScreenUtil
.
init
(
context
,
width:
750
,
height:
1334
,
allowFontScaling:
false
);
return
ExampleWidget
(
title:
'FlutterScreenUtil示例'
);
}
...
...
@@ -108,16 +109,14 @@ class _ExampleWidgetState extends State<ExampleWidget> {
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Text
(
'我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化'
,
style:
TextStyle
(
color:
Colors
.
black
,
fontSize:
24
.
sp
,
)),
Text
(
'我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化'
,
style:
TextStyle
(
color:
Colors
.
black
,
fontSize:
ScreenUtil
()
.
setSp
(
24
,
allowFontScalingSelf:
true
))),
Text
(
'我的文字大小在设计稿上是24px,不会随着系统的文字缩放比例变化'
,
style:
ts
.
t2
,
),
Text
(
'我的文字大小在设计稿上是24px,会随着系统的文字缩放比例变化'
,
style:
ts
.
t1
,
),
],
)
],
...
...
@@ -126,7 +125,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
floatingActionButton:
FloatingActionButton
(
child:
Icon
(
Icons
.
title
),
onPressed:
()
{
ScreenUtil
.
init
(
context
,
width:
1500
,
height:
1334
,
allowFontScaling:
false
);
ScreenUtil
.
init
(
context
,
width:
1500
,
height:
1334
,
allowFontScaling:
false
);
setState
(()
{});
},
),
...
...
example/lib/text_style.dart
0 → 100644
View file @
f4d9763
import
'package:flutter/material.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
class
TextStyles
{
TextStyle
t1
=
TextStyle
(
fontSize:
24
.
ssp
,
color:
Colors
.
black
);
TextStyle
t2
=
TextStyle
(
fontSize:
24
.
sp
,
color:
Colors
.
black
);
}
var
ts
=
TextStyles
();
class
TextStyle2
{
static
TextStyle2
ts2
;
factory
TextStyle2
()
{
if
(
ts2
==
null
)
{
ts2
=
TextStyle2
();
}
return
ts2
;
}
TextStyle
t1
=
TextStyle
(
fontSize:
24
.
ssp
,
color:
Colors
.
black
);
TextStyle
t2
=
TextStyle
(
fontSize:
24
.
sp
,
color:
Colors
.
black
);
}
...
...
lib/screenutil.dart
View file @
f4d9763
...
...
@@ -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
;
...
...
@@ -34,8 +34,8 @@ class ScreenUtil {
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
.
_
();
}
...
...
@@ -44,7 +44,7 @@ class ScreenUtil {
_instance
.
allowFontScaling
=
allowFontScaling
;
MediaQueryData
mediaQuery
=
MediaQuery
.
of
(
context
);
_pixelRatio
=
mediaQuery
.
devicePixelRatio
;
_pixelRatio
=
mediaQuery
.
devicePixelRatio
;
_screenWidth
=
mediaQuery
.
size
.
width
;
_screenHeight
=
mediaQuery
.
size
.
height
;
_statusBarHeight
=
mediaQuery
.
padding
.
top
;
...
...
@@ -117,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
));
}
...
...
Please
register
or
login
to post a comment