为什么80%的码农都做不了架构师?>>>
import 'package:flutter/material.dart'; import 'package:flutter_app/common/common_bar.dart'; class Point{ double x,y; Point(this.x,this.y); } class EventWidget extends StatefulWidget { @override StatecreateState() => new EventState(); } class EventState extends State { var point_1=new Point(100.0, 50.0); ChangePointX(double x){ setState(() { this.point_1.x=x; }); } ChangePointY(double y){ setState(() { this.point_1.y=y; }); } @override Widget build(BuildContext context) { double width=MediaQuery.of(context).size.width; return new Scaffold( appBar:commonBar('点击、拖动和其它手势', Icons.home), body: new Column( children: [ new Expanded( child: new Stack( children: [ new Positioned( left: 0.0, top: 15.5, child: new Container( width: 50.0, height: 50.0, color: Colors.blue, )), new Positioned( left: this.point_1.x, top: this.point_1.y, child: new GestureDetector( // 只能再GestureDetector 内使用时间 child: new Container( width: 50.0, height: 50.0, color: Colors.blue, ), //鼠标按下移动事件 onVerticalDragUpdate:(e){ var x=e.globalPosition.dx-20.0; var y=e.globalPosition.dy-100.0; // print(e.globalPosition.dy); this.ChangePointX(x); this.ChangePointY(y); }, ) ), new Positioned( left: 0.0, top: 155.5, child: new Container( width: 50.0, height: 50.0, color: Colors.blue, )) ], ), ) ], ), ); } }