问题描述
你好,我正在创建颤振应用程序并尝试绘制图像,我从下面的答案中成功地做到了
This is the main answer from where i can get idea about dropping pin on tap
From this answer i am drwaing image successfully
但问题是引脚没有绘制到精确的偏移(x&y)位置,我在这里附上了屏幕截图,这样你就可以得到更好的主意。
Here is the screen shot please take a look at the exact issue
return Scaffold(
appBar: AppBar(
title: Text(widget.title,style: TextStyle(color: Colors.white),),backgroundColor: Color.fromrGBO(86,35,127,1),brightness: Brightness.dark
),body: SafeArea(
top: true,bottom: true,left: true,right: true,child: Stack(
children: [
Listener(
onPointerDown: (PointerDownEvent event) {
Render@R_404_6277@ reference@R_404_6277@ = _paintKey.currentContext.findRenderObject();
Offset offset = reference@R_404[email protected](event.position); // here i am getting offset where user tapped
setState(() {
_offset = offset;
isDroppedPin = true;
});
if (widget.pinNo <= 5){
}else{
Toast.show("Maximum Pin Limit Reached",context,duration: Toast.LENGTH_SHORT,gravity: Toast.BottOM);
}
},child: InteractiveViewer(
minScale: 0.1,maxScale: 3,child: Stack(
children: [
new CustomPaint(
key: _paintKey,painter: new MyCustomPainter(_image,_offset),],Positioned.fill(
child: Align(
alignment: Alignment.bottomCenter,child: Container(
margin: EdgeInsets.fromLTRB(10,10,0),height: 50,child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Color.fromrGBO(86,// background
onPrimary: Colors.white,shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5)),// foreground
),onpressed: () {
if (isDroppedPin == false){
Toast.show("Please Add pin",gravity: Toast.BottOM);
}else{
Navigator.push(context,EOBAElementFormRoute(_offset.dx.toString(),_offset.dy.toString(),widget.title,widget.pinNo,widget.image_url,widget.type,widget.drawing_id));
}
},child: Container(
width: double.infinity,child: Text('Next',style: TextStyle(color: Colors.white,fontSize: 17,fontWeight: FontWeight.w500),textAlign: TextAlign.center,)
],)
);
这里是画图钉的班级
class MyCustomPainter extends CustomPainter {
ui.Image image;
final Offset _offset;
MyCustomPainter(this.image,this._offset) : super();
@override
Future paint(Canvas canvas,Size size) async {
if (image != null) {
canvas.drawImage(image,_offset,new Paint());
}
}
@override
bool shouldRepaint(MyCustomPainter other) => other._offset != _offset;
}
谁能知道为什么没有将图钉绘制到用户点击的确切位置
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)