Flutter小技巧总结之Flutter开发中的几个常用函数

/** 获取屏幕宽度 */
  static double getScreenWidth(BuildContext context) {
    return MediaQuery.of(context).size.width;
  }

  /** 获取屏幕高度 */
  static double getScreenHeight(BuildContext context) {
    return MediaQuery.of(context).size.height;
  }

  /** 获取系统状态栏高度 */
  static double getSysStatsHeight(BuildContext context) {
    return MediaQuery.of(context).padding.top;
  }


  

/** 返回两个日期相差的天数 */
static int daysBetween(DateTime a, DateTime b, [bool ignoreTime = false]) {
if (ignoreTime) {
  int v = a.millisecondsSinceEpoch ~/ 86400000 -
  b.millisecondsSinceEpoch ~/ 86400000;
if (v < 0) return -v;
  return v;
} else {
  int v = a.millisecondsSinceEpoch - b.millisecondsSinceEpoch;
 if (v < 0) v = -v;
  return v ~/ 86400000;
 }
}

 

 

posted on 2019-07-30 00:12  梁飞宇  阅读(399)  评论(0)    收藏  举报