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. [Gamma阶段]第八次Scrum Meeting

    Scrum Meeting博客目录 [Gamma阶段]第八次Scrum Meeting 基本信息 名称 时间 地点 时长 第八次Scrum Meeting 19/06/04 大运村寝室6楼 40min ...

  2. vs开启,Windows 10磁盘占用100%解决办法

    https://www.cnblogs.com/time-is-life/p/8888441.html 最后把Home Group相关的服务都改成禁用. 注意: 即使这两个服务没有启动也不行, 一定要 ...

  3. Densely semantically aligned person re-identification

    Densely semantically aligned person re-identification https://arxiv.org/abs/1812.08967

  4. spring.factories spring.schemas spring.handlers spring自动装配

    org.springframework.core.io.support.SpringFactoriesLoader —— public static final String FACTORIES_RE ...

  5. Centos新服务器需要安装的必备软件包

    yum install -y gcc gcc-c++ kernel-devel yum install -y pcre pcre-devel yum install -y zlib zlib-deve ...

  6. MySQL导数据笔记

    2019-12-16 9:08:43 星期一 MySQL 5.6 limit / order 有bug, 如果主键不是自增的, 只能全表导出导入, 增量导入导出的话会报主键重复 触发器: 批量导入数据 ...

  7. weixin-js-sdk

    场景:在h5移动端,实现分享朋友,分享朋友圈. 插曲:一开始我认为是不能做到分享的,主要是我从微信小程序的角度出发的,想着微信小程序都做不到分享朋友圈功能,那h5就更不能实现了,导致出现了错误的判断. ...

  8. intellij查找接口的实现类

    拿MyBatis的SqlSession为例 第一步:先找到这个接口 第二步:右击选择 再选择 第三步: 会得到如下 右击Closeable,因为SqlSession实现了它,选择Show Inplem ...

  9. dubbo 报错问题记录:may be version or group mismatch

    凌晨时候钉钉告警群里一直大量报错: 接口异常报警:项目:mp-rest,域名:inside-mp.01zhuanche.com,IP:10.30.3.60,接口地址:/api/v3/driverLog ...

  10. Appium基础之屏幕截图

    应用背景 在实际自动化项目运行过程中,很多时候App可以会出现各种异常,为了更好的定位问题,除了捕捉日志我们还需要对运行时的设备状态来进行截屏.从而达到一种“有图有真相”的效果. 截图方法 方法1 s ...