how does flutter make screen adaptation
how does flutter make screen adaptation
refer to https://github.com/OpenFlutte.
./*
* Created by on 2018/9/29.
* email: zhuoyuan93@gmail.com
*/
import 'package:flutter/material.dart';
class ScreenUtil {
static ScreenUtil instance = new ScreenUtil();
/// UI , px
/// Size of the phone in UI Design , px
double width;
double height;
/// "" false
/// allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings. The default is false.
bool allowFontScaling;
static MediaQueryData _mediaQueryData;
static double _screenWidth;
static double _screenHeight;
static double _pixelRatio;
static double _statusBarHeight;
static double _bottomBarHeight;
static double _textScaleFactor;
ScreenUtil({
this.width = 1080,
this.height = 1920,
this.allowFontScaling = false,
});
static ScreenUtil getInstance() {
return instance;
}
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;
_textScaleFactor = mediaQuery.textScaleFactor;
}
static MediaQueryData get mediaQueryData => _mediaQueryData;
///
/// The number of font pixels for each logical pixel.
static double get textScaleFactory => _textScaleFactor;
///
/// The size of the media in logical pixels (e.g, the size of the screen).
static double get pixelRatio => _pixelRatio;
/// dp
/// The horizontal extent of this size.
static double get screenWidthDp => _screenWidth;
/// dp
///The vertical extent of this size. dp
static double get screenHeightDp => _screenHeight;
/// px
/// The vertical extent of this size. px
static double get screenWidth => _screenWidth * _pixelRatio;
/// px
/// The vertical extent of this size. px
static double get screenHeight => _screenHeight * _pixelRatio;
/// dp
/// The offset from the top
static double get statusBarHeight => _statusBarHeight;
/// dp
/// The offset from the bottom.
static double get bottomBarHeight => _bottomBarHeight;
/// dpUIpx
/// The ratio of the actual dp to the design draft px
get scaleWidth => _screenWidth / instance.width;
get scaleHeight => _screenHeight / instance.height;
/// UI
/// ,.
/// Adapted to the device width of the UI Design.
/// Height can also be adapted according to this to ensure no deformation ,
/// if you want a square
setWidth(num width) => width * scaleWidth;
/// UI
/// UI,
/// ,.
/// UI
/// Highly adaptable to the device according to UI Design
/// It is recommended to use this method to achieve a high degree of adaptation
/// when it is found that one screen in the UI design
/// does not match the current style effect, or if there is a difference in shape.
setHeight(num height) => height * scaleHeight;
///
///@param [fontSize] UI,px.
///Font size adaptation method
///@param [fontSize] The size of the font on the UI design, in px.
///@param [allowFontScaling]
setSp(num fontSize) => allowFontScaling
? setWidth(fontSize)
: setWidth(fontSize) / _textScaleFactor;
}
Previous: Vue-awesome-swiper 3.1.3 error Maximum call stack size exceeded
Next: What is the difference between getFieldDecorator and getFieldProps in rc-form?
The page does the function of the page before the jump after the completion of the event, using the method of adding returnUrl on Url, but when testing on the mobile side, a pop-up window will appear to show the path of the page to be redirected before r...
problem 1: now the company is developing an activity that uses the H 5 interface to do it. Click on the pop-up window on the native app and enter my H5 interface. pass a user ID, ask me how my current H5 interface should receive the parameters passed ...
Why is the running environment of Wechat Mini Game JavaScriptCore on iOS and V8 on Android ? Why use two JS engines ? anyway, Wechat Mini Game running environment requires the ability to interpret JS code , while JavaScriptCore or V8 ...
how ionic3 projects are packaged with apk ...
do you have a boss to introduce in detail the specific process of packaging APP through H5 website and then putting it on the shelf? ...
...
using Taobao flexible, no matter using 1px or 1px converted rem, it cannot be displayed in the 1px frame of some wide-screen mobile phones. Do you have any better solution? ...
can css3 s flex layout be fully used in mobile hybrid development without compatibility issues? Is there no compatibility problem with flex in Wechat? ...
if the title is packed in mode 4, opening app will stay on the welcome page for a long time. What should I do? Find an effective solution, thank you. ...
at present, we try to use navigator as a route jump in the weex project. Depending on the platform, we have written a method to return the path navigatorurlwebweex playgroundAndroid studio now I especially want to achieve the successful use of the N...
the bosses react native web+H5 is very slow, android can t even click on the switch, and iOS is also very stuck. Is this a normal phenomenon or is there a problem with the code writing? If it is a normal phenomenon, we have a second solution is to bridg...
php...
1. Run the H5 project in the Uc browser on the mobile side, and click the button to select the phone to take photos. 2.2 3.MMP 4. Finally, the two images uploaded by the UC browser are the same, but there is no such bug 5 in other browsers. Later, t...
problem description rn does not display properly from ios to android compatible internal webview tested addeventlistener ( message ) does not trigger it has been confirmed that the event listening code is not executed because the window has not ...
rn needs to be implemented in app to share Mini Program to Wechat. the react-native-wechat previously used has been mentioned in issuse, but it is still not clear exactly how to do it link description I hope the boss who has done it can give me so...
how does cordova achieve the function of obtaining camera stream in real time like webRtc? webRtc cannot be used because it is compatible with ios,. the function that needs to be realized is that the real-time video stream of the front camera draws ...
after clicking on the repeat request, sometimes it shows a red cross, and sometimes it waits. It is normal to send a request directly on the mobile phone. this used to work, even after I did breakpoint once, even if I canceled the breakpoint. ...
problem description the packaged size of the project is 31MB, and the total size of the actual project code + static file is less than 1.1MB. (the same logic is only 12MB when using native Android) the environmental background of the problems and wh...
when loading js with the ready event, js was executed after trying browser forward and backward, mobile browser forward and backward, return, history return, and so on. the result suddenly returns that the js will not be executed on the mobile. Baidu ...
I d like to ask all the bosses. the Wechat public platform I applied for has been certified, so whether the Wechat open platform needs to be certified again. Thank you. ...