观察,

GestureDetector(
child: CustomPaint(painter: StudyPaint(points: _points)),
onPanEnd: (DragEndDetails details)=>_points.add(null),
onPanUpdate: (DragUpdateDetails details){
var a = details.globalPosition;
RenderBox referenceBox = context.findRenderObject();
Offset localPosition = referenceBox.globalToLocal(details.globalPosition);
print('a: $a, localposition: $localPosition');
setState(() {
_points = List.from(_points)..add(localPosition);
});
},
),

  

减了3个 h

import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: HomePage(),
);
}
} class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return HomePageState();
}
} class HomePageState extends State<HomePage> {
List<Offset> _points = <Offset>[]; @override
Widget build(BuildContext context) {
// print(_points);
var h = MediaQuery.of(context).padding.top;
var b = MediaQuery.of(context).padding.bottom;
// print('h: $h, b: $b'); return Scaffold(
appBar: AppBar(title: Text('Painter'),),
body: Container(
width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height-h,
child: Stack(
children: <Widget>[
GestureDetector(
// child:
onPanEnd: (DragEndDetails details)=>_points.add(null),
onPanUpdate: (DragUpdateDetails details){
var a = details.globalPosition;
var x = Offset(a.dx, a.dy-h-h-h);
RenderBox referenceBox = context.findRenderObject();
Offset localPosition = referenceBox.globalToLocal(details.globalPosition);
// print('a: $a, x: $x, localposition: $localPosition');
setState(() {
_points = List.from(_points)..add(x);
});
},
),
CustomPaint(painter: StudyPaint(points: _points)),
],
)
),
);
}
} class StudyPaint extends CustomPainter {
StudyPaint({this.points});
List<Offset> points; @override
void paint(Canvas canvas, Size size) {
print(points);
Paint paint = Paint()
..color = Colors.blue
..strokeCap = StrokeCap.round
..isAntiAlias = true
..strokeJoin = StrokeJoin.bevel
..strokeWidth = 12.0; for(int i=0; i<points.length; i++){
if(points[i]!=null && points[i+1]!=null)
canvas.drawLine(points[i], points[i+1], paint);
} } @override
bool shouldRepaint(StudyPaint other) => other.points!=points;
}

  

import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: HomePage(),
);
}
} class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return HomePageState();
}
} class HomePageState extends State<HomePage> {
List<Offset> _points = <Offset>[]; @override
Widget build(BuildContext context) {
// print(_points);
var h = MediaQuery.of(context).padding.top;
print('h: $h');
return Scaffold(
appBar: AppBar(title: Text('Painter'),),
body: Center(
child: Container(
width: double.infinity, height: double.infinity,
child: GestureDetector(
child: CustomPaint(painter: StudyPaint(points: _points)),
onPanEnd: (DragEndDetails details)=>_points.add(null),
onPanUpdate: (DragUpdateDetails details){
var a = details.globalPosition;
RenderBox referenceBox = context.findRenderObject();
Offset localPosition = referenceBox.globalToLocal(details.globalPosition);
print('a: $a, localposition: $localPosition');
setState(() {
_points = List.from(_points)..add(localPosition);
});
},
),
),
),
);
}
} class StudyPaint extends CustomPainter {
StudyPaint({this.points});
List<Offset> points; @override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = Colors.blue
..strokeCap = StrokeCap.round
..isAntiAlias = true
..strokeWidth = 12.0
..strokeJoin = StrokeJoin.bevel; for(int i=0; i<points.length; i++){
if(points[i]!=null && points[i+1]!=null)
canvas.drawLine(points[i], points[i+1], paint);
} } @override
bool shouldRepaint(StudyPaint other) => other.points!=points;
}

  

global position的更多相关文章

  1. MRPT笔记——使用编译好的MRPT库建立VS2013项目

    接着上一篇<MRPT在VS2013中的配置>,下面接收如何使用编译好的MRPT建立工程项目. 一.设置环境变量 上一篇中,配置MRPT时,使用到了几个相关库,opencv.zlib.wxW ...

  2. [SLAM]2D激光扫描匹配方法

    1.Beam Model 2.Likehood field for k=1:size(zt,1) if zt(k,2)>0 d = -grid_dim/2; else d = grid_dim/ ...

  3. JQ弹出框移动-插件分享~~~

    <script src="js/jQuery8.3.js" type="text/javascript"></script> <s ...

  4. 【异构计算】OpenCL矩阵转置

    介绍 矩阵转置,主要的技巧还是利用好local memory ,防止local memory,以及glabol memory的读取尽量是合并读写. 完整代码一: main.cpp代码 #include ...

  5. English trip V2 - 5 Technology Teacher:Taylor Key:adjective + preposition

    In this lesson you will learn to talk about technology and innovation. 课上内容(Lesson) What is your fav ...

  6. AGV

    AGV AGV是(Automated Guided Vehicle)的缩写,意即“自动导引运输车”,是指装备有电磁或光学等自动导引装置,它能够沿规定的导引路径行驶,具有安全保护以及各种移载功能的运输车 ...

  7. Gmapping笔记

    2D-slam 激光slam: 开源代码的比较HectorSLAM Gmapping KartoSLAM CoreSLAM LagoSLAM 作者:kint_zhao 原文:https://blog. ...

  8. QT 窗口拖拽移动实现

    我们知道,要实现窗口移动可以直接鼠标点住窗口的标题栏实现拖拽移动,这是窗口默认的行为,在QT中的事件响应函数为moveEvent. 但是现实中经常需要鼠标点住窗口客户区域实现窗口的拖拽移动,代码实现如 ...

  9. GPS定位基本原理浅析

    位置服务已经成为越来越热的一门技术,也将成为以后所有移动设备(智能手机.掌上电脑等)的标配.而定位导航技术中,目前精度最高.应用最广泛的,自然非GPS莫属了.网络上介绍GPS原理的专业资料很多,而本文 ...

随机推荐

  1. mac下使用java测试iOS推送

    首先mac下有很多现在的测试iOS推送软件,为什么要用java程序测试呢: 因为大多数后台推送服务可能是JAVA开发的,那么为了验证我们在MAC上导出的推送证书文件是否正确: 制作开发证书的iOS开发 ...

  2. Shared variable in python's multiprocessing

    Shared variable in python's multiprocessing https://www.programcreek.com/python/example/58176/multip ...

  3. Filebeat的使用

    前言 logstash本身就可以具有文件数据采集的功能了,为什么还需要在前面加一层filebeat?理由如下:logstash是使用Java编写,插件是使用JRuby编写,对机器的资源要求会比较高,在 ...

  4. Python3基础 from...import...as 解决局部导入时的函数名重复问题

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  5. 分布式事务二TCC

    分布式事务解决方案之TCC 4.1.什么是TCC事务 TCC是Try.Confirm.Cancel三个词语的缩写,TCC要求每个分支事务实现三个操作:预处理Try.确认Confirm.撤销Cancel ...

  6. redis支持远程接入的安全防护问题

    如果我们没有启用保护模式,支持远程接入,启用默认端口6379,而且是用root用户启动的,那么基本上redis就是在裸奔了,人家分分钟搞你没商量. 我们模拟一下,现在机器A(ip假设为10.100.1 ...

  7. Struts2数据封装

    首先是简单数据类型的封装 jsp页面 <%@ page contentType="text/html;charset=UTF-8" language="java&q ...

  8. shell脚本检查是否存在tun0虚拟网卡,若不不存在服务器更改port,并重启服务器,客户端修改port,并重新启动客户端

    openvp 客户端 /home 目录下各脚本文件名 [root@jira home]# ls openvpn_server_restart.sh openvpn_tunnel_monitor.sh ...

  9. webapi+swagger ui 文档描述

    代码:GitHub swagger ui在我们的.NET CORE和.NET Framework中的展现形式是不一样的,如果有了解的,在.NET CORE中的是比.NET Framework好的.两张 ...

  10. python中判断对象类型的函数——isinstance

    isinstance是Python中的一个内建函数.是用来判断一个对象的变量类型. isinstance(object, class-or-type-or-tuple) 如果参数object是clas ...