Flutter获取屏幕信息

2020-12-16  本文已影响0人  精简明了
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Global {
  static Global _instance;

  Global._internal();

  factory Global() {
    if (_instance == null) {
      _instance = Global._internal();
    }
    return _instance;
  }

  static MediaQueryData mediaQueryData = MediaQueryData.fromWindow(window);
  static double screenWidth = mediaQueryData.size.width;
  static double screenHeight = mediaQueryData.size.height;

  // 获取上边距和下边距的值(主要用于刘海屏)
  static double paddingTop = mediaQueryData.padding.top;
  static double paddingBottom = mediaQueryData.padding.bottom;
}
上一篇下一篇

猜你喜欢

热点阅读