void getPositions() {
final RenderBox renderBox = scheduleForDayKey.currentContext!.findRenderObject();
final position = renderBox.localToGlobal(Offset.zero);
print("POSITION of Red: $position ");
}
这部分用红色下划线:scheduleForDayKey.currentContext!.findRenderObject()
当我悬停时,它告诉我错误:A value of type 'RenderObject' can't be assigned to a variable of type 'RenderBox'.
可能这段代码已经过时了,或者是因为我在互联网上看到了很多类似的代码示例,出于某种原因对我不起作用。
最佳答案
试着写:
final RenderBox renderBox = scheduleForDayKey.currentContext!
.findRenderObject() as RenderBox;
关于flutter - 'RenderObject' 类型的值不能分配给 'RenderBox' 类型的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67550315/