skip to Main Content

I have screen where show showcase screen component. Now these components can be anything and I want to dynamically find radius of the widget. Which I will pass to a custom painter to draw that shape with radius.

I have tried using finding anything useful in RenderObject but haven’t found anything.

Is there any method which can provide me RRect object similar to below?

    final box = globalKey.currentContext!.findRenderObject() as RenderBox;
    final rect = size & box.localToGlobal(Offset.zero);

2

Answers


  1. Chosen as BEST ANSWER

    I resolved it by using context.widget like this,

    double getRadius() {
        BuildContext? context = key!.currentContext;
        var parent = context?.widget;
        if (parent is Parent) {
          var gestureDetector = (parent).child;
          if (gestureDetector is GestureDetector) {
            var clipRRect = gestureDetector.child;
            if (clipRRect is ClipRRect) {
              return (clipRRect.borderRadius as BorderRadius).topRight.x;
            }
          }
        }
     return 0;
    }
    

  2. A RenderObject will not be disposed until you replace it by another RenderObject of a different type, or remove the associated widget from the widget tree.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search