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
june lee
2024-05-08 11:57:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-05-07 21:57:12 -0500
Commit
987c462b49e787a099b9699172bf33f2a2e6701e
987c462b
1 parent
6bafe6f6
remove dart:io for support web (#550)
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
27 deletions
lib/src/screen_util.dart
lib/src/screen_util.dart
View file @
987c462
...
...
@@ -3,7 +3,8 @@
* email: zhuoyuan93@gmail.com
*/
import
'dart:io'
;
import
'package:flutter/foundation.dart'
show
kIsWeb
,
defaultTargetPlatform
;
import
'dart:math'
show
min
,
max
;
import
'dart:ui'
as
ui
show
FlutterView
;
...
...
@@ -241,34 +242,40 @@ class ScreenUtil {
double
setSp
(
num
fontSize
)
=>
fontSizeResolver
?.
call
(
fontSize
,
_instance
)
??
fontSize
*
scaleText
;
DeviceType
deviceType
()
{
DeviceType
deviceType
;
switch
(
Platform
.
operatingSystem
)
{
case
'android'
:
case
'ios'
:
deviceType
=
DeviceType
.
mobile
;
if
((
orientation
==
Orientation
.
portrait
&&
screenWidth
<
600
)
||
(
orientation
==
Orientation
.
landscape
&&
screenHeight
<
600
))
{
deviceType
=
DeviceType
.
mobile
;
}
else
{
deviceType
=
DeviceType
.
tablet
;
DeviceType
deviceType
(
BuildContext
context
)
{
var
deviceType
=
DeviceType
.
web
;
final
screenWidth
=
MediaQuery
.
of
(
context
).
size
.
width
;
final
screenHeight
=
MediaQuery
.
of
(
context
).
size
.
height
;
final
orientation
=
MediaQuery
.
of
(
context
).
orientation
;
if
(
kIsWeb
)
{
deviceType
=
DeviceType
.
web
;
}
else
{
bool
isMobile
=
defaultTargetPlatform
==
TargetPlatform
.
iOS
||
defaultTargetPlatform
==
TargetPlatform
.
android
;
bool
isTablet
=
(
orientation
==
Orientation
.
portrait
&&
screenWidth
>=
600
)
||
(
orientation
==
Orientation
.
landscape
&&
screenHeight
>=
600
);
if
(
isMobile
)
{
deviceType
=
isTablet
?
DeviceType
.
tablet
:
DeviceType
.
mobile
;
}
else
{
switch
(
defaultTargetPlatform
)
{
case
TargetPlatform
.
linux
:
deviceType
=
DeviceType
.
linux
;
break
;
case
TargetPlatform
.
macOS
:
deviceType
=
DeviceType
.
mac
;
break
;
case
TargetPlatform
.
windows
:
deviceType
=
DeviceType
.
windows
;
break
;
case
TargetPlatform
.
fuchsia
:
deviceType
=
DeviceType
.
fuchsia
;
break
;
default
:
break
;
}
break
;
case
'linux'
:
deviceType
=
DeviceType
.
linux
;
break
;
case
'macos'
:
deviceType
=
DeviceType
.
mac
;
break
;
case
'windows'
:
deviceType
=
DeviceType
.
windows
;
break
;
case
'fuchsia'
:
deviceType
=
DeviceType
.
fuchsia
;
break
;
default
:
deviceType
=
DeviceType
.
web
;
}
}
return
deviceType
;
}
...
...
Please
register
or
login
to post a comment