Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get borderRadius of parent widget in Flutter

Is there any way at all we can get the parent widgets borderRadius property? If it makes things any clearer, this is the context of asking the question: I'm authoring the glass package on pub.dev/packages/glass. It allows you to convert any widget to a glass version by calling an extension .asGlass() method on it, which involved a ClipRRect widget. However, since I don't know if the widget on which asGlass is called has a borderRadius, sometimes the glass effect extends over the borders of the parent widget (i.e. the widget has rounded borders, while the glass effect has rectangular borders). So is there any way I can get the borderRadius or any property at all from the calling widget without the user having to pass it explicitly?

like image 639
Zac Avatar asked Jan 23 '26 17:01

Zac


1 Answers

Passing the value of a borderRadius is a cleaner approach and should be followed.

You can make an optional radius argument with default value of 0. A rectangle is rendered unless a borderRadius is specified.

asGlass(BorderRadiusGeometry borderRadius = BorderRadius.zero){...}

Now whenever your parent has a border radius just pass it in:

var _borderRadius = BorderRadius.circular(10);
Card(
 ...,
 borderRadius: _borderRadius,
).asGlass(_borderRadius);