Skip to content

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

@Huanxin1997

Description

@Huanxin1997

你好,我使用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来实现自动更新?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions