flutter - 如何将小部件动态添加到手势检测器的偏移位置颤动
问题描述
[![Image Sample][1]][1] 下面这张图片是我添加到我的颤振应用程序中的。我希望它工作的方式是,一旦用户点击任何位置,我就会向它添加一些指示器小部件。我有我的逻辑,它返回手势检测器的点击坐标点。它返回一个偏移位置,例如 Offset(172.5, 298.5)
Stack(
children: [
GestureDetector(
onTapDown: _handleTapDown,
onTap: () {
},
child: Container(
child: Image.asset(
images[index],
height: 500,
width: double.infinity,
)),
),
Positioned(
right: 20.0,
bottom: 70.0,
child: Container(
width: 100,
height: 48,
child: MainButton(
color: primaryColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Image.asset(
'images/rotate.png',
height: 16,
width: 16,
),
SizedBox(
width: 14,
),
Text(
"Turn",
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 14,
fontFamily: 'Lato',
color: Colors.white,
fontWeight: FontWeight.w700,
),
),
],
),
onPressed: () {
setState(() {
if (index == 2) {
index = 0;
} else {
index++;
}
});
},
),
),
),
],
),
void _handleTapDown(TapDownDetails details) {
final RenderBox referenceBox = context.findRenderObject();
setState(() {
_tapPosition = referenceBox.globalToLocal(details.globalPosition);
print(_tapPosition);
});
}
现在,如何确保指示器小部件根据其点击位置出现在用户点击的任何点上?[1]:https ://i.stack.imgur.com/pHz2om.png
解决方案
推荐阅读
- kubernetes - initContainers 和主容器的不同 restartPolicy
- python - Python:pandas data_reader -> plotly candelstick graph not identify date column from tiingo stock data api import
- arrays - Angular 向我返回一个未定义的数组,但我之前已定义
- inno-setup - 在 Inno Setup 的一个不错的任务对话框窗口中显示有关下载文件的错误哈希的信息
- html - 如何用图标或文字替换 html 输入时间中的 PM 和 AM
- c - 二进制 + 的无效操作数(具有 'struct student' 和 'int')
- c# - 如何在 mongo 中使用 C# .net 运行自定义查询?
- react-native - 如何通过堆栈导航将数据传递到反应原生选项卡上的特定屏幕?
- reactjs - NextJs CORS 问题
- git - Git文件夹和github存储库连接问题