Code Monkey home page Code Monkey logo

Comments (8)

lizhuoyuan avatar lizhuoyuan commented on July 2, 2024 1

@OHeroJ 毫无疑问是的.
所以我想自己写一个继承state的组件 , 然后把初始化封装进去会不会稍微好一点

from flutter_screenutil.

yn-tadpole avatar yn-tadpole commented on July 2, 2024 1

不是利用context拿到正确的数据,是因为不是在程序一启动就获取相应的值,或者build方法执行时间靠后,碰巧而已。
下面才是有效的临时处理方式,让程序等一下,200ms后再执行。

void main () {
    Future.delayed(Duration(milliseconds: 200)).then((val) {
        runApp(MyApp());
      }, onError: (error) {});
    }
}

from flutter_screenutil.

lizhuoyuan avatar lizhuoyuan commented on July 2, 2024 1

为什么是200ms不是100ms?
谁都不知道具体多久能拿到屏幕数据
万一我10ms就拿到了还要多等190ms?
不要意识流吧

反正 利用context去拿数据是没问题的
你喜欢用你的方式也ok

from flutter_screenutil.

lizhuoyuan avatar lizhuoyuan commented on July 2, 2024

关于window这个东西
在release没模式下
拿到窗口数据的时间是未知的.
利用context去获取的话是肯定有数据的
我的测试结果是这样
下图为示例.

如果有什么方法可以不需要context一样能拿到数据的话, 求指点
image
image

from flutter_screenutil.

OHeroJ avatar OHeroJ commented on July 2, 2024

在混合情况下,都需要初始化这个单例是否太过麻烦

from flutter_screenutil.

yn-tadpole avatar yn-tadpole commented on July 2, 2024

@lizhuoyuan 关于window这个东西在release没模式下拿到窗口数据的时间确实是刚开始拿不到数据,过一会儿又能拿到。这应该算Flutter的一个BUG。
但是利用context去获取有数据只是因为它慢了一点,问题没有暴露出来,因为MediaQuery实际也是调用了window。下图(media_query.dart源码)为证:
MediaQuery

我为这个事情也是烦心了好久。正在考虑人为制造一点延时,保证在release模式下启动慢一点,以保证可以正确显示一个动画效果的启动页。

from flutter_screenutil.

lizhuoyuan avatar lizhuoyuan commented on July 2, 2024

@yn-tadpole

反正现在利用context是肯定能正确拿到屏幕数据的,虽然它也是用的window的数据.
所以就只能这样了
还没有找到更好的方式

from flutter_screenutil.

doudouaixiaoyu avatar doudouaixiaoyu commented on July 2, 2024

不建议用windows 这种方式获取屏幕大小,发布为release时,启动太快,导致为0

from flutter_screenutil.

Related Issues (20)

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.