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,并以超链接形式标明文章原始出处,否则将 ...
随机推荐
- Java finally未被执行的情况
一种是先执行了用于终止程序的System.exit()方法,或进程被关闭 还有一种情况是,当前线程一直在执行,在一些业务逻辑里面跳不出来,看上去就像finally一直未被执行 线程被终止的时候也会执行 ...
- 安装anaconda和tensorflow(windows)
Anaconda安装时勾选All User和启用环境变量可切换为清华镜像conda config --add channels https://mirrors.tuna.tsinghua.edu.cn ...
- 主题模型(LDA)(一)--通俗理解与简单应用
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_39422642/article/de ...
- Python爬虫实例项目
WechatSogou [1]- 微信公众号爬虫.基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫,返回结果是列表,每一项均是公众号具体信息字典. DouBanSpider [2]- ...
- Incorrect string value: '\xF0\x9F\x98\xAD",...' for column 'commentContent' at row 1
我分为下面三个步骤来解决: (1):修改mysql数据库的编码为uft8mb4 (2):修改数据表的编码为utf8mb4 (3):修改连接数据库的连接代码 更改数据库编码:ALTER DATABASE ...
- Kafka的安装与使用(转)
9.1 Kafka 基础知识 9.1.1 消息系统 点对点消息系统:生产者发送一条消息到queue,一个queue可以有很多消费者,但是一个消息只能被一个消费者接受,当没有消费者可用时,这个消息会被保 ...
- C++中rapidxml用法
转载:https://www.cnblogs.com/rainbow70626/p/7586713.html 解析xml是第三方库很多,例如:tingxml,这次学习一下rapidxml,rapidx ...
- CentOS使用yum安装最新版nginx步骤
sudo yum install yum-utilsvi /etc/yum.repos.d/nginx.repo 输入: [nginx-stable]name=nginx stable repoba ...
- java中wait()和sleep()的区别;notify()和notifyall()区别
先说两个概念:锁池和等待池 锁池:假设线程A已经拥有了某个对象(注意:不是类)的锁,而其它的线程想要调用这个对象的某个synchronized方法(或者synchronized块),由于这些线程在进入 ...
- selenium===使用docker搭建selenium分布式测试环境
准备: #请在此之前先了解,selenium grid :参考:selenium-grid ,下载地址,win-本地部署过程 >>>环境准备: Linux操作系统 >>& ...