pixel_fix 0.0.1 copy "pixel_fix: ^0.0.1" to clipboard
pixel_fix: ^0.0.1 copied to clipboard

原生写法的屏幕适配

pixel_fix #

pub package

Plugin for adapting Android and iOS screen size.

Usage: #

Add dependency: #

dependencies:
  pixel_fix: ^0.0.1

Add import: #

import 'package:pixel_fix/pixel_fix.dart';

init: #

void main() {
  InnerWidgetsFlutterBinding.initPixel(1242, 3);
}

use: #

void main() {
  InnerWidgetsFlutterBinding.ensureInitialized()
    ..attachRootWidget(MyApp())
    ..scheduleWarmUpFrame();
}

原理:
​基于修改系统的缩放值来实现改变系统绘制的大小。

具体实现:
重写主要是createViewConfiguration这个方法

优缺点:
1、不能动态设置ratio值,即不能根据屏幕宽高和设计稿的比例获取真实比例(不能兼容不同设计稿)
2、用法简单:在使用是没有任何要求,与flutter原生相同。开发人员无感知
3、因为手动重写了gestures/binding.dart的一些方法,随着Flutter版本的升级,需要不断修改InnerWidgetsFlutterBinding的代码。

1
likes
25
pub points
0%
popularity

Publisher

unverified uploader

原生写法的屏幕适配

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on pixel_fix