GithubHelp home page GithubHelp logo

fluttertest's Introduction

flutter 屏幕适配 demo main

一种一劳永逸的全局适配方式

tip

请不要适用MediaQuery.of(context)大小相关方法,window同理,默认MediaQuery适用的系统原本的大小, 非用使用,需要重写MaterialApp,
大小直接使用context.size,或者从size或者constraints获取

效果

320x480
320x480
1080x1920
1080x1920

原理 (具体代码 main

1.更改配置的 ViewConfiguration 的size和devicePixelRatio (ViewConfiguration 这个类再 RenderView 里赋值,而RenderView是 renderObject树的根,在布局和绘制的过程中,会根据ViewConfiguration的值来做由父向子的布局绘制操作)
2.PointerDataPacket 从引擎冲过来的事件,默认采用的是 系统的devicePixelRatio ,这里就需要适用我们的值 复写 initInstances() 内部 ui.window.onPointerDataPacket=_handlePointerDataPacket 赋值以下

void _handlePointerDataPacket(ui.PointerDataPacket packet) {
    _pendingPointerEvents.addAll(PointerEventConverter.expand(
        packet.data,
        // 适配事件的转换比率,采用我们修改的
        getAdapterRatio()));
    if (!locked) _flushPointerEventQueue();
  }

fluttertest's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.