Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+0027 [ 数据 ] 不在MaterialApp内如何获取屏幕尺寸等 MediaQueryData 数据 #61

Open
toly1994328 opened this issue Sep 17, 2020 · 1 comment
Labels
point The point of Flutter

Comments

@toly1994328
Copy link
Owner

toly1994328 commented Sep 17, 2020

MaterialApp内 ,MediaQuery可以通过.of 获取MediaQueryData是因为 MaterialApp内部已经存在MediaQuery组件来提供数据。
找到源头,效仿即可。

45951600310732_ pic_hd

@toly1994328
Copy link
Owner Author

//确保初始化
WidgetsFlutterBinding.ensureInitialized();
//获取MediaQueryData
MediaQueryData data = MediaQueryData.fromWindow(WidgetsBinding.instance.window);
print(data.size);

@toly1994328 toly1994328 added the point The point of Flutter label Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
point The point of Flutter
Projects
None yet
Development

No branches or pull requests

1 participant