Flutter获取屏幕信息

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;
}

你可能感兴趣的:(Flutter获取屏幕信息)