Flutter cast RenderObject to RenderBox
1,868
The solution was easier than I thought:
simply use as
like this:
RenderBox renderBox =
actionKey.currentContext!.findRenderObject()! as RenderBox;
Author by
Chris
Updated on December 29, 2022Comments
-
Chris over 1 year
I am trying to follow this tutorial creating a
DropDown
. But I can not copy his code becauseFlutter 2.0
is forbidding it because I can of these lines:void findDropdownData() { RenderBox renderBox = actionKey.currentContext!.findRenderObject()!; height = renderBox.size.height; width = renderBox.size.width; Offset? offset = renderBox.localToGlobal(Offset.zero); xPosition = offset!.dx; yPosition = offset.dy; }
As you can see I tried do add some
!
and?
but it is still not working. The main issue is thatfindRenderObject
returnsRenderObject
but I need it to be aRenderBox
... Any idea what's wrong here? Can not figure it out..