forked from OpenFlutter/flutter_screenutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f76f59
commit eb6f740
Showing
9 changed files
with
786 additions
and
623 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
# Generated by pub on 2018-09-21 00:18:30.075689. | ||
analyzer:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.32.4/lib/ | ||
args:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/args-1.5.0/lib/ | ||
async:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/async-2.0.8/lib/ | ||
boolean_selector:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/boolean_selector-1.0.4/lib/ | ||
charcode:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/charcode-1.1.2/lib/ | ||
collection:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/collection-1.14.11/lib/ | ||
convert:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/convert-2.0.2/lib/ | ||
crypto:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/crypto-2.0.6/lib/ | ||
csslib:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/csslib-0.14.5/lib/ | ||
flutter:file:///d:/flutter/packages/flutter/lib/ | ||
flutter_test:file:///d:/flutter/packages/flutter_test/lib/ | ||
front_end:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/front_end-0.1.4/lib/ | ||
glob:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/glob-1.1.7/lib/ | ||
html:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/html-0.13.3+3/lib/ | ||
http:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/http-0.11.3+17/lib/ | ||
http_multi_server:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/http_multi_server-2.0.5/lib/ | ||
http_parser:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/http_parser-3.1.3/lib/ | ||
io:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/io-0.3.3/lib/ | ||
js:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/js-0.6.1+1/lib/ | ||
json_rpc_2:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/json_rpc_2-2.0.9/lib/ | ||
kernel:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/kernel-0.3.4/lib/ | ||
logging:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/logging-0.11.3+2/lib/ | ||
matcher:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/matcher-0.12.3+1/lib/ | ||
meta:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.1.6/lib/ | ||
mime:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/mime-0.9.6+2/lib/ | ||
multi_server_socket:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/ | ||
node_preamble:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/node_preamble-1.4.4/lib/ | ||
package_config:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/package_config-1.0.5/lib/ | ||
package_resolver:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/package_resolver-1.0.4/lib/ | ||
path:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/path-1.6.2/lib/ | ||
plugin:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/plugin-0.2.0+3/lib/ | ||
pool:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/pool-1.3.6/lib/ | ||
pub_semver:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/pub_semver-1.4.2/lib/ | ||
quiver:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/quiver-2.0.0+1/lib/ | ||
shelf:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf-0.7.3+3/lib/ | ||
shelf_packages_handler:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_packages_handler-1.0.4/lib/ | ||
shelf_static:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_static-0.2.8/lib/ | ||
shelf_web_socket:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/shelf_web_socket-0.2.2+4/lib/ | ||
sky_engine:file:///d:/flutter/bin/cache/pkg/sky_engine/lib/ | ||
source_map_stack_trace:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_map_stack_trace-1.1.5/lib/ | ||
source_maps:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_maps-0.10.7/lib/ | ||
source_span:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_span-1.4.1/lib/ | ||
stack_trace:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/stack_trace-1.9.3/lib/ | ||
stream_channel:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/stream_channel-1.6.8/lib/ | ||
string_scanner:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/string_scanner-1.0.4/lib/ | ||
term_glyph:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/term_glyph-1.0.1/lib/ | ||
test:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/test-1.3.0/lib/ | ||
typed_data:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/typed_data-1.1.6/lib/ | ||
utf:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/utf-0.9.0+5/lib/ | ||
vector_math:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/vector_math-2.0.8/lib/ | ||
vm_service_client:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/vm_service_client-0.2.6/lib/ | ||
watcher:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/watcher-0.9.7+10/lib/ | ||
web_socket_channel:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/web_socket_channel-1.0.9/lib/ | ||
yaml:file:///d:/flutter/.pub-cache/hosted/pub.flutter-io.cn/yaml-2.1.15/lib/ | ||
# Generated by pub on 2018-09-29 11:16:33.432789. | ||
analyzer:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/analyzer-0.32.4/lib/ | ||
args:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/args-1.5.0/lib/ | ||
async:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/async-2.0.8/lib/ | ||
boolean_selector:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/boolean_selector-1.0.4/lib/ | ||
charcode:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/charcode-1.1.2/lib/ | ||
collection:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/collection-1.14.11/lib/ | ||
convert:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/convert-2.0.2/lib/ | ||
crypto:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/crypto-2.0.6/lib/ | ||
csslib:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/csslib-0.14.5/lib/ | ||
flutter:file:///D:/flutter/packages/flutter/lib/ | ||
flutter_test:file:///D:/flutter/packages/flutter_test/lib/ | ||
front_end:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/front_end-0.1.4/lib/ | ||
glob:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/glob-1.1.7/lib/ | ||
html:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/html-0.13.3+3/lib/ | ||
http:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/http-0.11.3+17/lib/ | ||
http_multi_server:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/http_multi_server-2.0.5/lib/ | ||
http_parser:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/http_parser-3.1.3/lib/ | ||
io:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/io-0.3.3/lib/ | ||
js:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/js-0.6.1+1/lib/ | ||
json_rpc_2:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/json_rpc_2-2.0.9/lib/ | ||
kernel:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/kernel-0.3.4/lib/ | ||
logging:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/logging-0.11.3+2/lib/ | ||
matcher:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/matcher-0.12.3+1/lib/ | ||
meta:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/meta-1.1.6/lib/ | ||
mime:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/mime-0.9.6+2/lib/ | ||
multi_server_socket:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/multi_server_socket-1.0.2/lib/ | ||
node_preamble:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/node_preamble-1.4.4/lib/ | ||
package_config:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/package_config-1.0.5/lib/ | ||
package_resolver:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/package_resolver-1.0.4/lib/ | ||
path:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/path-1.6.2/lib/ | ||
plugin:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/plugin-0.2.0+3/lib/ | ||
pool:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/pool-1.3.6/lib/ | ||
pub_semver:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/pub_semver-1.4.2/lib/ | ||
quiver:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/quiver-2.0.0+1/lib/ | ||
shelf:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/shelf-0.7.3+3/lib/ | ||
shelf_packages_handler:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/shelf_packages_handler-1.0.4/lib/ | ||
shelf_static:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/shelf_static-0.2.8/lib/ | ||
shelf_web_socket:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/shelf_web_socket-0.2.2+4/lib/ | ||
sky_engine:file:///D:/flutter/bin/cache/pkg/sky_engine/lib/ | ||
source_map_stack_trace:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/source_map_stack_trace-1.1.5/lib/ | ||
source_maps:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/source_maps-0.10.7/lib/ | ||
source_span:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/source_span-1.4.1/lib/ | ||
stack_trace:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/stack_trace-1.9.3/lib/ | ||
stream_channel:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/stream_channel-1.6.8/lib/ | ||
string_scanner:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/string_scanner-1.0.4/lib/ | ||
term_glyph:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/term_glyph-1.0.1/lib/ | ||
test:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/test-1.3.0/lib/ | ||
typed_data:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/typed_data-1.1.6/lib/ | ||
utf:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/utf-0.9.0+5/lib/ | ||
vector_math:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/vector_math-2.0.8/lib/ | ||
vm_service_client:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/vm_service_client-0.2.6/lib/ | ||
watcher:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/watcher-0.9.7+10/lib/ | ||
web_socket_channel:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/web_socket_channel-1.0.9/lib/ | ||
yaml:file:///C:/Users/Frank/AppData/Roaming/Pub/Cache/hosted/pub.flutter-io.cn/yaml-2.1.15/lib/ | ||
flutter_screenutil:lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,74 @@ | ||
/* | ||
* Created by 李卓原 on 2018/9/20. | ||
* Created by 李卓原 on 2018/9/29. | ||
* email: zhuoyuan93@gmail.com | ||
* 设计稿设备尺寸默认为 1080 * 1920 px | ||
*/ | ||
|
||
import 'dart:ui'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ScreenUtil { | ||
//请修改成你的设计稿的尺寸 | ||
static ScreenUtil instance = new ScreenUtil(width: 1080, height: 1920); | ||
static ScreenUtil instance = new ScreenUtil(); | ||
|
||
//设计稿的设备尺寸修改 | ||
int designWidth; | ||
int designHeight; | ||
int _designWidth; | ||
|
||
int _designHeight; | ||
|
||
static MediaQueryData _mediaQueryData; | ||
static double _screenWidth; | ||
static double _screenHeight; | ||
static double _pixelRatio; | ||
static double _statusBarHeight; | ||
|
||
static double _bottomBarHeight; | ||
|
||
ScreenUtil({int width, int height}) { | ||
designWidth = width; | ||
designHeight = height; | ||
_designWidth = width; | ||
_designHeight = height; | ||
} | ||
|
||
static ScreenUtil getInstance() { | ||
return instance; | ||
} | ||
|
||
//设备的像素密度 | ||
static double pixelRatio = window.devicePixelRatio; | ||
void init(BuildContext context) { | ||
MediaQueryData mediaQuery = MediaQuery.of(context); | ||
_mediaQueryData = mediaQuery; | ||
_pixelRatio = mediaQuery.devicePixelRatio; | ||
_screenWidth = mediaQuery.size.width; | ||
_screenHeight = mediaQuery.size.height; | ||
_statusBarHeight = mediaQuery.padding.top; | ||
_bottomBarHeight = _mediaQueryData.padding.bottom; | ||
} | ||
|
||
static MediaQueryData get mediaQueryData => _mediaQueryData; | ||
|
||
///设备的像素密度 | ||
static double get pixelRatio => _pixelRatio; | ||
|
||
//当前设备宽度 px | ||
static double screenWidth = window.physicalSize.width; | ||
///当前设备宽度 px | ||
static double get screenWidth => _screenWidth * _pixelRatio; | ||
|
||
//当前设备高度 px | ||
static double screenHeight = window.physicalSize.height; | ||
///当前设备高度 px | ||
static double get screenHeight => _screenHeight * _pixelRatio; | ||
|
||
//状态栏高度 刘海屏会更高 | ||
static double statusBarHeight = window.padding.top; | ||
///状态栏高度 刘海屏会更高 | ||
static double get statusBarHeight => _statusBarHeight * _pixelRatio; | ||
|
||
//底部安全区距离 | ||
static double bottomBarHeight = window.padding.bottom; | ||
///底部安全区距离 | ||
static double get bottomBarHeight => _bottomBarHeight * _pixelRatio; | ||
|
||
//相对于设计稿放大的倍数 | ||
double get scaleWidth => screenWidth / instance.designWidth / pixelRatio; | ||
///相对于设计稿放大的倍数 | ||
get scaleWidth => _screenWidth / instance._designWidth; | ||
|
||
double get scaleHeight => screenHeight / instance.designHeight / pixelRatio; | ||
get scaleHeight => _screenHeight / instance._designHeight; | ||
|
||
/** | ||
* 根据设计稿的设备宽度适配 | ||
* 高度也根据这个来做适配可以保证不变形 | ||
*/ | ||
///根据设计稿的设备宽度适配 | ||
///高度也根据这个来做适配可以保证不变形 | ||
setWidth(int width) => width * scaleWidth; | ||
|
||
/** | ||
* 根据设计稿的设备高度适配 | ||
* 当发现设计稿中的一屏显示的与当前样式效果不符合时, | ||
* 或者形状有差异时,高度适配建议使用此方法 | ||
* 高度适配主要针对想根据设计稿的一屏展示一样的效果 | ||
*/ | ||
/// 根据设计稿的设备高度适配 | ||
/// 当发现设计稿中的一屏显示的与当前样式效果不符合时, | ||
/// 或者形状有差异时,高度适配建议使用此方法 | ||
/// 高度适配主要针对想根据设计稿的一屏展示一样的效果 | ||
setHeight(int height) => height * scaleHeight; | ||
} |
Oops, something went wrong.