我正在尝试为GridView中的Inkwell Widget添加一个爆炸效果,但我需要找到它的偏移量。目前我已经尝试了以下方法:
GridView.builder(
itemCount: 10,
itemBuilder: (ctx, ind) {
return InkWell(
onTap: () async {
try {
final RenderBox box = ctx.findRenderObject();
Offset position = box.localToGlobal(Offset.zero,
ancestor: context.findRenderObject()
);
double x = position.dx;
double y = position.dy;
double w = box.size.width;
Future.delayed(Duration(milliseconds: 100)).then(
(_) => _particleField.lineExplosion(x, y, w)
);
} catch (e) {
print(e);
}
},
child: Center(
child: Text("${ind + 1},000,000")
),
);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3
),
)
但是我遇到了这个错误:
类型'RenderSliverGrid'不是类型'RenderBox'的子类型
RenderSliver
而不是RenderBox
。 - Xihuny