InheritedWidget and screen
self:
import 'package:flutter/material.dart'; class GrantScreen {
static double _width, _height;
static double _physicalWidth, _physicalHeight;
static double _top, _bottom;
static double _scaleWidth, _scaleHeight;
static double _textScale;
static double _pixelRatio; GrantScreen(BuildContext context){
_physicalWidth = MediaQuery.of(context).size.width;
_physicalHeight = MediaQuery.of(context).size.height;
_top = MediaQuery.of(context).padding.top;
_bottom = MediaQuery.of(context).padding.bottom;
_textScale = MediaQuery.of(context).textScaleFactor;
_width = 375.0;
_height = 667.0;
_scaleWidth = _physicalWidth / _width;
_scaleHeight = _physicalHeight / _height;
_pixelRatio = MediaQuery.of(context).devicePixelRatio;
} get top => _top / _scaleHeight;
get bottom => _bottom / _scaleHeight;
get scaleWidth => _scaleWidth;
get scaleHeight => _scaleHeight;
get width => _width;
get height => _height;
get pixelRatio => _pixelRatio;
get physicalWidth => _physicalWidth;
get physicalHeight => _physicalHeight; setWidth(double w) => w * _scaleWidth;
setHeight(double h) => h * _scaleHeight; setFontSize(double f, [bool allowScale=true]) =>
allowScale? setWidth(f)/_textScale : f/_textScale; getGlobalPosition(DragDownDetails details){
double dx = details.globalPosition.dx / _scaleWidth;
double dy = details.globalPosition.dy / _scaleHeight;
return DragDownDetails(globalPosition: Offset(dx, dy));
}
}
main
import 'package:flutter/material.dart';
import 'screen.dart'; main() => runApp(MaterialApp(
home: MyApp(),
)); class MyApp extends StatelessWidget { @override
Widget build(BuildContext context) {
var x = MediaQuery.of(context).size;
print('original size: $x'); GrantScreen screen = GrantScreen(222, 444, context);
return RootWidget(
child: HomePage(),
screen: screen,
);
}
} class RootWidget extends InheritedWidget {
RootWidget({Key key, @required this.child, this.screen}):super(key:key);
final GrantScreen screen;
final Widget child; static RootWidget of(BuildContext context){
return context.inheritFromWidgetOfExactType(RootWidget);
} @override
bool updateShouldNotify(InheritedWidget oldWidget) {
return true;
}
} class HomePage extends StatelessWidget { @override
Widget build(BuildContext context) {
var s = RootWidget.of(context).screen;
return Scaffold(
appBar: AppBar(title: Text('ABC', style: TextStyle(fontSize: 22),),),
body: GestureDetector(
onPanDown: (DragDownDetails details){
print('mmmmmmmmmmmmmmmmmmmmmm');
print(details);
print(s.getGlobalPosition(details));
print('new top: ${s.top}');
print(MediaQuery.of(context).padding.top);
print('mmmmmmmmmmmmmmmmmmmmmmmm');
},
child: Container(
width: double.infinity,height: double.infinity,
color: Colors.grey,
child: Column(
children: <Widget>[
Text('Text', style: TextStyle(fontSize: s.setFontSize(44, true)),),
Text('Text', style: TextStyle(fontSize: s.setFontSize(44, false)),),
Text('Text', style: TextStyle(fontSize: 44),),
],
),
),),
);
}
}
screen:
import 'package:flutter/material.dart'; class GrantScreen {
static double _width, _height;
static double _physicalWidth, _physicalHeight;
static double _top, _bottom;
static double _scaleWidth, _scaleHeight;
static double _textScale;
static double _pixelRatio; GrantScreen(double w, double h, BuildContext context){
_physicalWidth = MediaQuery.of(context).size.width;
_physicalHeight = MediaQuery.of(context).size.height;
_top = MediaQuery.of(context).padding.top;
_bottom = MediaQuery.of(context).padding.bottom;
_textScale = MediaQuery.of(context).textScaleFactor;
_width = w;
_height = h;
_scaleWidth = _physicalWidth / w;
_scaleHeight = _physicalHeight / h;
_pixelRatio = MediaQuery.of(context).devicePixelRatio;
} get top => _top / _scaleHeight;
get bottom => _bottom / _scaleHeight;
get scaleWidth => _scaleWidth;
get scaleHeight => _scaleHeight;
get width => _width;
get height => _height;
get pixelRatio => _pixelRatio;
get physicalWidth => _physicalWidth;
get physicalHeight => _physicalHeight; setWidth(double w) => w * _scaleWidth;
setHeight(double h) => h * _scaleHeight; setFontSize(double f, [bool allowScale=true]) =>
allowScale? setWidth(f)/_textScale : f/_textScale; getGlobalPosition(DragDownDetails details){
double dx = details.globalPosition.dx / _scaleWidth;
double dy = details.globalPosition.dy / _scaleHeight;
return DragDownDetails(globalPosition: Offset(dx, dy));
}
}
InheritedWidget and screen的更多相关文章
- 断电不断网——Linux的screen
title: 断电不断网--Linux的screen author:青南 date: 2015-01-01 20:20:23 categories: [Linux] tags: [linux,scre ...
- screen命令
基本用法 screen -S testname 在这里面执行命令,即使终端突出,进程也不会断掉 screen -list查看有哪些screen screen -r testname 恢复
- SSH远程会话管理工具 - screen使用教程
一.screen命令是什么? Screen是一个可以在多个进程之间多路复用一个物理终端的全屏窗口管理器.Screen中有会话的概念,用户可以在一个screen会话中创建多个screen窗口,在每一个s ...
- screen:多重视窗管理程序
screen:多重视窗管理程序 screen [-S SCREEN_NAME]: 创建窗口,可指定窗口名称,如果不指定,则是ID.$HOSTNAME screen -ls: 列出所有的screen窗口 ...
- [LeetCode] Sentence Screen Fitting 调整屏幕上的句子
Given a rows x cols screen and a sentence represented by a list of words, find how many times the gi ...
- 关于媒体查询 @Media Screen 与响应式
其实CSS2中已经有了媒体查询的概念,但是CSS3中媒体查询功能更加的强大! 首先,我们来看一个小例子 设置媒体查询的 Max Width ,改变窗口大小到600px的时候就会触发一下代码: @med ...
- 利用@media screen实现网页布局的自适应
利用@media screen实现网页布局的自适应 优点:无需插件和手机主题,对移动设备友好,能够适应各种窗口大小.只需在CSS中添加@media screen属性,根据浏览器宽度判断并输出不同的长宽 ...
- 了解screen对象的常用视图属性
前面的话 screen对象基本上只用来表明客户端的能力,其中包括浏览器窗口外部的显示器的信息,如像素高度和宽度等.每个浏览器中的screen对象都包含着各不相同的属性.本文将详细介绍screen对象的 ...
- 列表屏幕(List Screen)
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
随机推荐
- JavaScript初探系列(十一)——ES6
一.前言 ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,已经在 2015 年 6 月正式发布了.它的目标,是使得 JavaScript 语言可以用来编写复 ...
- mac 下面用dd 制作u盘启动
用dd来把安装包烧到U盘的,发现U盘变小了,mac磁盘工具也不能格式化,就只好用命令行了.diskutil list #1.找到U盘的代号 比如disk1diskutil unmountDisk /d ...
- Set JAVA_HOME in windows cmd(在windows 命令行中修改JAVA_HOME)
set JAVA_HOME=jrepathset PATH=%JAVA_HOME%\bin;%PATH%注意这里没有引号.这样就不需要在我的电脑属性中修改java_home了,以及重启命令行了.对于程 ...
- Transaction 那点事儿
Transaction 那点事儿 https://my.oschina.net/huangyong/blog/160012
- tensorflow 笔记 15:如何使用 Supervisor
如何使用Supervisor在不使用Supervisor的时候,我们的代码经常是这么组织的 variables ... ops ... summary_op ... merge_all_summari ...
- SpringCloud 微服务中 @Async 注解自定义线程池 引发的aop 问题
背景 在 使用springCloud 的@Async注解来做异步操作时,想自定义其线程池. 引发问题 自定义完线程池后,发现代码里并没有使用自定义线程池里的线程,于是新建一个demo工程,一样的配置代 ...
- 转 mysql distinct函数 与 免密码登录 与 查看表的结构
#########sample 1 mysql中去重 distinct 用法 在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重 ...
- SSAS 项目部署失败的问题
在创建SSAS项目过程中,创建数据源.数据源视图.多维数据集.纬度等一切都没有问题.但是在“进程”这一步的时候,发现总是报错,提示如下.OLE DB 错误: OLE DB 或 ODBC 错误 : 用户 ...
- php代码规范->如何写出规范且易于理解的项目代码-ZX版
2019年5月17日10:50:12 前序: 目前是想到哪写到哪,后面有时间在整理成具体文章 很多时候,PHP代码风格过于自由,导致一个项目有N多种写法风格,有些人为了自己认为的技术"高&q ...
- 1-1docker加速器
配置加速器 #编译配置 sudo vim /etc/docker/daemon.json #加入下面的数据 { "registry-mirrors": ["https:/ ...