void getPositions() {
final RenderBox renderBox = scheduleForDayKey.currentContext!.findRenderObject();
final position = renderBox.localToGlobal(Offset.zero);
print("POSITION of Red: $position ");
}
Run Code Online (Sandbox Code Playgroud)
这部分用红色下划线:
scheduleForDayKey.currentContext!.findRenderObject()
Run Code Online (Sandbox Code Playgroud)
当我悬停时,它告诉我错误:
“RenderObject”类型的值不能分配给“RenderBox”类型的变量。
可能这段代码已经过时了,或者是因为我在互联网上看到了很多类似的代码示例,但由于某种原因对我不起作用。
小智 14
试着写:
final RenderBox renderBox = scheduleForDayKey.currentContext!
.findRenderObject() as RenderBox;
Run Code Online (Sandbox Code Playgroud)
小智 10
对我来说,这段代码适用于我的 sdk:">=2.12.0 <3.0.0"
最终 RenderBox box = context.findRenderObject() as RenderBox;
| 归档时间: |
|
| 查看次数: |
1126 次 |
| 最近记录: |