【发布时间】:2018-11-17 12:48:07
【问题描述】:
我正在尝试在点击位置的图像上添加一个按钮。 我已经设法通过使用 onTapUp 的详细参数来获得点击位置。
但是,当用户点击图片时,我无法添加图标按钮。
下面的代码显示了我的示例。
class ArticlesShowcase extends StatelessWidget {
final commentWidgets = List<Widget>();
@override
Widget build(BuildContext context) {
return new GestureDetector(
child: new Center(
child: Image.network(
'https://via.placeholder.com/300x500',
),
),
onTapUp: (detail) {
final snackBar = SnackBar(
content: Text(detail.globalPosition.dx.toString() +
" " +
detail.globalPosition.dy.toString()));
Scaffold.of(context).showSnackBar(snackBar);
new Offset(detail.globalPosition.dx, detail.globalPosition.dy);
var btn = new RaisedButton(
onPressed: () => {},
color: Colors.purple,
child: new Text(
"Book",
style: new TextStyle(color: Colors.white),
),
);
commentWidgets.add(btn);
},
);
}
}
我尝试在列表中添加按钮但没有机会。
【问题讨论】: