Flutter: MediaQuery
使用MediaQuery根据不同的屏幕大小调整应用程序的UI布局。 您还可以使用它根据用户布局首选项进行UI调整。
class _MyHomeState extends State<MyHome> {\
@override
Widget build(BuildContext context) {
MediaQueryData deviceData = MediaQuery.of(context);
// 屏幕信息
Size screenSize = deviceData.size;
// 设备方向
Orientation deviceOrientation = deviceData.orientation;
bool isPortrait = true;
if (deviceOrientation == Orientation.portrait) {
// print('竖屏:更高');
isPortrait = true;
} else if (deviceOrientation == Orientation.landscape) {
// print('横屏: 更宽');
isPortrait = false;
}
// 默认字体大小
double fontScaling = deviceData.textScaleFactor;
// 屏幕各个部分,flutter自动提供了一个安全区域
EdgeInsets notchInset = deviceData.padding;
print(notchInset);
// 辅助信息,是否禁用了动画
bool noAnimations = deviceData.disableAnimations;
print(noAnimations);
// 系统UI的大小
print(MediaQuery.of(context).viewPadding.bottom);
// 当前App亮度模式
Brightness screenContrast = deviceData.platformBrightness;
print(screenContrast);
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo'),
),
body: Column(
children: <Widget>[
Container(
child: Text(
screenSize.width.toString(),
style: TextStyle(fontSize: 30),
),
),
Container(
child: Text('默认字体大小: $fontScaling'),
),
Container(
height: 100.0,
decoration: BoxDecoration(
color: isPortrait ? Colors.green : Colors.purple,
),
),
],
),
);
}
}
Flutter: MediaQuery的更多相关文章
- Flutter获取屏幕宽高和Widget大小
我们平时在开发中的过程中通常都会获取屏幕或者 widget 的宽高用来做一些事情,在 Flutter 中,我们可以使用如下方法来获取屏幕或者 widget 的宽高. MediaQuery 一般情况下, ...
- Flutter 强大的MediaQuery控件
注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 MediaQuery 通常情况下,不会直接将MediaQu ...
- flutter系列之:查询设备信息的利器:MediaQuery
目录 简介 MediaQuery详解 MediaQuery的属性 MediaQuery的构造函数 MediaQuery的使用 总结 简介 移动的开发中,大家可能最头疼的就是不同设备的规格了,现在设备这 ...
- Flutter学习(一)之MaterialApp和Scaffold组件使用详解
一,前言: MaterialApp和Scaffold是Flutter提供的两个Widget,其中: MaterialApp是一个方便的Widget,它封装了应用程序实现Material Design所 ...
- flutter 学习零碎知识点01
1.Expanded组件 占满可用空间 -----可以到达类似flex布局中 第一列占用大量空间,所以它必须包装在Expanded widget中. 写死的高度改成Expanded自动撑满屏幕如果还 ...
- Flutter 开发小技巧
1.命令行运行flutter run之后iOS报错:Could not install build/ios/iphones/Runner.app on XXXXX. try lunching Xcod ...
- flutter 列表展示
内容: 1.列表展示 2.轮播图 3.其他 本次的内容也是在上一节的基础上进行操作 我们就搞这个story模块. 目录: story.dart story主页面 import 'package:fl ...
- flutter屏幕适配
现在的手机品牌和型号越来越多,导致我们平时写布局的时候会在个不同的移动设备上显示的效果不同, 比如我们的设计稿一个View的大小是300px,如果直接写300px,可能在当前设备显示正常,但到了其他设 ...
- flutter中使用webview
首先要安装一个插件:flutter_webview_plugin dependencies: flutter_webview_plugin: ^0.2.1+2 使用方法: new MaterialAp ...
随机推荐
- Java 执行过程中的内存模型
一.前言 本文的主要工作:尝试以时间顺序追踪一遍 Java 执行的整个过程,以及展示 JVM 中内存模型的相应变化. 本文的主要目的:希望能够通过 Java 执行过程的冰山一角,增进对编程语言工作原理 ...
- Java——数据类型
数据类型分类 基本数据类型: 数值型: 整数类型(byte,short,int,long): 浮点类型(float,double): 字符型(char): 布尔值(boolean): 引用数据类型: ...
- spark-submit提交spark任务的具体参数配置说明
spark-submit提交spark任务的具体参数配置说明 1.spark提交任务常见的两种模式 2.提交任务时的几个重要参数 3.参数说明 3.1 executor_cores*num_execu ...
- HttpURLConnection下载文件流
package com.loan.modules; import sun.net.www.protocol.file.Handler; import java.io.*; import java.ne ...
- Flink-v1.12官方网站翻译-P027-State Schema Evolution
状态方案的演变 Apache Flink流媒体应用通常被设计为无限期或长时间运行.与所有长期运行的服务一样,应用程序需要更新以适应不断变化的需求.这对于应用程序所针对的数据模式也是一样的,它们会随着应 ...
- linux(4)Linux 文件内容查看
查看文件内容总览 cat 由第一行开始显示文件内容 tac 从最后一行开始显示,可以看出 tac 是 cat 的倒着写! nl 显示的时候,顺道输出行号! more 一页一页的显示文件内容 less ...
- for循环实现的一些小例子
1.1-10阶乘和 package HELLO; public class exercise5 { /** 1-10阶乘和 */ public static void main(String[] ar ...
- Centos7 搭建Nginx+rtmp+hls直播推流服务器
1 准备工具 使用yum安装git [root~]# yum -y install git 下载nginx-rtmp-module,官方github地址 // 通过git clone 的方式下载到服务 ...
- Linux-源码安装及FPM打包
目录 源码安装 制作RPM包(使用FPM工具) 安装rpm后要执行的脚本(优化版) 源码安装 这里举例Nginx的源码安装,需要前往Nginx官网找到稳定版本源码安装包下载. ## 源码安装nginx ...
- leetcode11 盛水容器 贪心
这道题,总感觉做过... 先理解题意,何为容器 容器 要求水面高度相同 于是体积就是长方形,高度有两块较高板的低板决定,宽度由两块板间距离决定. 考虑当前最优解,就贪心 从两边开始向内,若能使得体积变 ...