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. DNS基本操作详解

    在很多人看来,DNS只是为外部提供DNS解析服务(我以前也是这么认为的,直到膝盖中了一箭),但作为互联网的基础设施,DNS远没有想象的那么简单.如果你没有听说过DNS查询.反向解析.zone传输.动态 ...

  2. 《微信小程序商城开发实战》唐磊,全网真实评价截图,不吹不黑,全部来自网友的真实评价

    偶尔看了下网友的销量和评价,感觉还不错,因为市面上大多关于小程序的书籍可能写的不够全面,要么只是点到为止的大致罗列,要么就是只简单介绍一下小程序的 界面设计这块.这样很难给学习小程序开发的人一个完成的 ...

  3. Pushing state-of-the-art in 3D content understanding

    Pushing state-of-the-art in 3D content understanding 2019-10-31 06:34:08 This blog is copied from: h ...

  4. SpringBoot——配置文件占位符

    在配置文件中采用: ${random.int} 获取一个随机值.

  5. spring mvc aop拦截controller层获取RequestBody反序列化后参数

    最近,为了解耦,把一逻辑从interceptor抽出来,放在aop中处理,需要得到RequestBody.如下: @Aspect @Configuration public class CheckAs ...

  6. 让ie10/11支持非单页面的vue/es6

    为了满足某些客户的要求,最近让前端同学实现了ie 10(windows 7)/11(windows 10)支持多页面的vue/es6,基本参考如下: https://www.cnblogs.com/n ...

  7. epool与select有什么区别

    select在一个进程中打开的最大fd是有限制的,由FD_SETSIZE设置,默认值是2048.不过 epoll则没有这个限制,它所支持的fd上限是最大可以打开文件的数目,这个数字一般远大于2048, ...

  8. 简述 IntentFilter(意图过滤器)

    1.什么是IntentFilter ? IntentFilter翻译成中文就是“意图过滤器”,主要用来过滤隐式意图.当用户进行一项操作的时候,Android系统会根据配置的 “意图过滤器” 来寻找可以 ...

  9. 解决:Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceMode

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/Eric_K1m/article/deta ...

  10. 将本地文件夹添加到git仓库

    1.git init; 2.git add . 3.git commit -m "初始化" 4.git remote add origin https://github.com/g ...