美文网首页
Flutter获取屏幕信息

Flutter获取屏幕信息

作者: 精简明了 | 来源:发表于2020-12-16 17:05 被阅读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;
    }
    

    相关文章

      网友评论

          本文标题:Flutter获取屏幕信息

          本文链接:https://www.haomeiwen.com/subject/fdcogktx.html