Comments (8)
@OHeroJ 毫无疑问是的.
所以我想自己写一个继承state的组件 , 然后把初始化封装进去会不会稍微好一点
from flutter_screenutil.
不是利用context拿到正确的数据,是因为不是在程序一启动就获取相应的值,或者build方法执行时间靠后,碰巧而已。
下面才是有效的临时处理方式,让程序等一下,200ms后再执行。
void main () {
Future.delayed(Duration(milliseconds: 200)).then((val) {
runApp(MyApp());
}, onError: (error) {});
}
}
from flutter_screenutil.
为什么是200ms不是100ms?
谁都不知道具体多久能拿到屏幕数据
万一我10ms就拿到了还要多等190ms?
不要意识流吧
反正 利用context去拿数据是没问题的
你喜欢用你的方式也ok
from flutter_screenutil.
关于window这个东西
在release没模式下
拿到窗口数据的时间是未知的.
利用context去获取的话是肯定有数据的
我的测试结果是这样
下图为示例.
如果有什么方法可以不需要context一样能拿到数据的话, 求指点
from flutter_screenutil.
在混合情况下,都需要初始化这个单例是否太过麻烦
from flutter_screenutil.
@lizhuoyuan 关于window这个东西在release没模式下拿到窗口数据的时间确实是刚开始拿不到数据,过一会儿又能拿到。这应该算Flutter的一个BUG。
但是利用context去获取有数据只是因为它慢了一点,问题没有暴露出来,因为MediaQuery实际也是调用了window。下图(media_query.dart源码)为证:
我为这个事情也是烦心了好久。正在考虑人为制造一点延时,保证在release模式下启动慢一点,以保证可以正确显示一个动画效果的启动页。
from flutter_screenutil.
反正现在利用context是肯定能正确拿到屏幕数据的,虽然它也是用的window的数据.
所以就只能这样了
还没有找到更好的方式
from flutter_screenutil.
不建议用windows 这种方式获取屏幕大小,发布为release时,启动太快,导致为0
from flutter_screenutil.
Related Issues (20)
- BorderRadiusExtension and RadiusExtension named wrong HOT 2
- some text widgets in build mode is missing HOT 18
- i update to flutter 3.19.5 the package dosen't work any more HOT 7
- ScreenUtils is best Utils for Flutter developer. HOT 1
- 5.9.0 oppo colorOS 14.0 Android14列表item有时会空白 HOT 3
- flutter_screenutil 5.9.0, Android phones can run with the screen turned off and wiget will be lost HOT 2
- 关于我使用ScreenUtilInit这种方式初始化,builder会调用两次,导致跳转页面会多生成一个 HOT 7
- u
- 横竖屏切换布局错乱 HOT 13
- Problem rendering in tablet size HOT 3
- 新版本 v5.9.2 以及以上版本,输入框无法正常弹出? HOT 3
- UI crashes in release mode HOT 2
- [Feature/Enhancement] Request for max and min screen size
- [Feature/Enhancement] Does not take the MediaQueryData of the parent
- Containers have extra space on bottom in ios
- flutter_screenutil 6.0.0-alpha.1 HOT 1
- Provide a concise title for your issue, e.g., "Error: The getter 'backgroundColor' isn't defined for the class 'ThemeData'".
- Integration with device_preview to correctly update MediaQueryData
- Text Visibility Issue in Release Mode
- How to set the maximum scale of the fontSize? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_screenutil.