height top-level property

dynamic get height

此方法用於獲取設備視口高度。

Implementation

get height {
  // 因App啟動過快,導致取得裝置尺吋取不到,若取不到,則直接給固定值,在master那邊再重新抓取裝置尺吋
  if (size.height == 0) {
    size = const Size(380, 780);
  }

  final view = PlatformDispatcher.instance.views.first;
  final statusBar = view.padding.top / view.devicePixelRatio;
  final screenHeight = size.height - statusBar;

  // 如果取得不到高度,就回傳預設值
  if (screenHeight == 0) {
    return 780; // fallback 預設值
  }
  return screenHeight;
}