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

折叠屏设备适配刷新问题 #57

Open
Huanxin1997 opened this issue Nov 2, 2023 · 0 comments
Open

折叠屏设备适配刷新问题 #57

Huanxin1997 opened this issue Nov 2, 2023 · 0 comments

Comments

@Huanxin1997
Copy link

你好,我使用ScreenUtil来作为产品的自适应方案。我希望在折叠屏设备折叠状态发生变化的时候,能自动更新页面UI元素尺寸。
当前情况:
使用如下方法,需要手动setState()或调用MediaQuery.of(context)才能实现。

/// 仅支持纵屏。
  /// returns the size after adaptation according to the screen width.(unit dp or pt)
  /// 返回根据屏幕宽适配后尺寸(单位 dp or pt)
  /// size 单位 dp or pt
  double getWidth(double size) {
    return _screenWidth == 0.0 ? size : (size * _screenWidth / _designW);
  }

  /// 仅支持纵屏。
  /// returns the size after adaptation according to the screen height.(unit dp or pt)
  /// 返回根据屏幕高适配后尺寸(单位 dp or pt)
  /// size unit dp or pt
  double getHeight(double size) {
    return _screenHeight == 0.0 ? size : (size * _screenHeight / _designH);
  }

其中,ScreenUtil中的某些方法中,包含执行MediaQuery.of(context)逻辑,可以实现自动刷新

  /// screen width
  /// 当前屏幕 宽
  static double getScreenW(BuildContext context) {
    MediaQueryData mediaQuery = MediaQuery.of(context);
    return mediaQuery.size.width;
  }

  /// screen height
  /// 当前屏幕 高
  static double getScreenH(BuildContext context) {
    MediaQueryData mediaQuery = MediaQuery.of(context);
    return mediaQuery.size.height;
  }

请问第一种情况是否有办法解决,还是只能手动setState来实现自动更新?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant