/*
*@Author: XianKaiQun
*@Date: 2020-04-20 17:37:45
 * @LastEditors  : WuWei
 * @LastEditTime : 2021-11-25 17:42:05
*@Descripttion: 
*/

import 'dart:ui' as ui;

extension ExtensionAdapt on num {
  ///适配转换函数  类似小程序rpx
  double get pt => this.toDouble() * _adaptUnit;
  double get ipt => this.toDouble() * _adaptUnit;
}

/// 设置全局最大最小字号， 暂时没用上
double getProperPt(num) {
  if (num < 14) {
    return 14;
  } else if (num > 20) {
    return 20;
  } else {
    return num;
  }
}

///获取1pt比例
///如果获取失败，则返回原始比例
double get _adaptUnit {
  final physicalSize = ui.window.physicalSize;
  final width = (physicalSize.width < physicalSize.height)
      ? physicalSize.width
      : physicalSize.height;

  final devicePixelRatio = ui.window.devicePixelRatio;
  if (width == 0 ||
      devicePixelRatio == 0 ||
      (width / devicePixelRatio / 375.0) < 0.96) return 1.0;
  return (width / devicePixelRatio / 375.0) >= 1.3
      ? 1.3
      : (width / devicePixelRatio / 375.0);
}
