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的更多相关文章

  1. 断电不断网——Linux的screen

    title: 断电不断网--Linux的screen author:青南 date: 2015-01-01 20:20:23 categories: [Linux] tags: [linux,scre ...

  2. screen命令

    基本用法 screen -S testname 在这里面执行命令,即使终端突出,进程也不会断掉 screen -list查看有哪些screen screen -r testname 恢复

  3. SSH远程会话管理工具 - screen使用教程

    一.screen命令是什么? Screen是一个可以在多个进程之间多路复用一个物理终端的全屏窗口管理器.Screen中有会话的概念,用户可以在一个screen会话中创建多个screen窗口,在每一个s ...

  4. screen:多重视窗管理程序

    screen:多重视窗管理程序 screen [-S SCREEN_NAME]: 创建窗口,可指定窗口名称,如果不指定,则是ID.$HOSTNAME screen -ls: 列出所有的screen窗口 ...

  5. [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 ...

  6. 关于媒体查询 @Media Screen 与响应式

    其实CSS2中已经有了媒体查询的概念,但是CSS3中媒体查询功能更加的强大! 首先,我们来看一个小例子 设置媒体查询的 Max Width ,改变窗口大小到600px的时候就会触发一下代码: @med ...

  7. 利用@media screen实现网页布局的自适应

    利用@media screen实现网页布局的自适应 优点:无需插件和手机主题,对移动设备友好,能够适应各种窗口大小.只需在CSS中添加@media screen属性,根据浏览器宽度判断并输出不同的长宽 ...

  8. 了解screen对象的常用视图属性

    前面的话 screen对象基本上只用来表明客户端的能力,其中包括浏览器窗口外部的显示器的信息,如像素高度和宽度等.每个浏览器中的screen对象都包含着各不相同的属性.本文将详细介绍screen对象的 ...

  9. 列表屏幕(List Screen)

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

随机推荐

  1. 微信token介绍

    这里的微信token 有以下三种 1.小程序的token  (appid+appsecret=token) 2.一个是第三方平台token(comment_appid+comment_appsecre ...

  2. [python]pypy优化python性能

    下载地址:https://pypy.org/download.html # python2.7版本 yum install pypy # python3.6版本https://bitbucket.or ...

  3. 【转】SQL2008 链接Oracle 调用存储过程

    1. SQL链接ORACLE 都是可视化的操作 如下图: 红色框选的是oracle的数据驱动,如果没有这个驱动 那需要单独安装oracle的client端 装完以后就有了. 2.在创建之前,在SQLS ...

  4. QT自定义信号和槽

    最近项目中使用到QT,在此记录一下QT的核心,信号与槽: QObject::connect(const QObject *sender, const char *signal, const QObje ...

  5. Create table as select

    create table xxx as select create table table1 =; 根据table2的表结构,创建tables1 create table table1 as sele ...

  6. 【GMT43智能液晶模块】例程二十:LAN_DNS实验——域名解析

    源代码下载链接: 链接:https://pan.baidu.com/s/16EW6AYpHpXljmBdNvMJM7g提取码:6lyk 复制这段内容后打开百度网盘手机App,操作更方便哦 GMT43购 ...

  7. SDN实验---Mininet实验(模拟多数据中心带宽实验)

    补充:NameError: name 'buffer' is not defined >>> import sys >>> ,): ... buffer = mem ...

  8. java js ur特殊格式处理 json 特殊格式处理

    url特殊格式处理: js中使用 encodeURIComponent() 编码对应的value $.ajax({ type: "post", url: "/tb_are ...

  9. Webpack 4 SplitChunksPlugin配置方案(转)

    通常情况下我们的 WebApp 是有我们的自身代码和第三方库组成的,我们自身的代码是会常常变动的,而第三方库除非有较大的版本升级,不然是不会变的,所以第三方库和我们的代码需要分开打包,我们可以给第三方 ...

  10. replace的回调函数。

    今天在看算法时,看到一些题目,感觉replace的回调函数好奇葩,$0 .$1什么的: JS的replace方法: str.replace(regexp|substr, newSubStr|funct ...