void getPositions() {
final RenderBox renderBox = scheduleForDayKey.currentContext!.findRenderObject();
final position = renderBox.localToGlobal(Offset.zero);
print("POSITION of Red: $position ");
}
This part is underlined with red:
scheduleForDayKey.currentContext!.findRenderObject()
When I hover, it tells me the error:
A value of type 'RenderObject' can't be assigned to a variable of type 'RenderBox'.
Maybe this section of code is outdated or something because I see a lot of similar code examples on the internet, which for some reason don't work for me.
A value of type 'Type' can't be assigned to a variable of type 'RenderBox'. Sorry, something went wrong. A value of type 'Type' can't be assigned to a variable of type 'RenderBox'. It should be RenderBox box = key.currentContext!.findRenderObject () as RenderBox;
As the error itself says Try changing the type of the variable, or casting the right-hand type to 'RenderBox'. like mentioned above, should resolve your issue. Closing this as resolved.
A value of type 'Type' can't be assigned to a variable of type 'RenderBox'. It should be RenderBox box = key.currentContext!.findRenderObject () as RenderBox;
Try writing:
final RenderBox renderBox = scheduleForDayKey.currentContext!
.findRenderObject() as RenderBox;
for me this code work with my for sdk: ">=2.12.0 <3.0.0"
final RenderBox box = context.findRenderObject() as RenderBox;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With