Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter overflow: hidden analogue

Tags:

flutter

dart

Is there any flutter widget that prevents the children to paint outside a Container by any mean?

I have this container with a child that may get some transformations (such as scale and rotate) and therefore can be painted outside

I want to limit the children's painting to only inside the parent Container, just like a div with CSS overflow:hidden; would behave.

A sample:

return Container( // the one with overflow hidden -ish behavior
   height: 300.0,
   child: TheTransformingChild() // the one that can get bigger that container
)
like image 964
Renan C. Araujo Avatar asked Nov 01 '18 18:11

Renan C. Araujo


2 Answers

There is - what you're looking for is a combination of OverflowBox or SizedOverflowBox and ClipRect, or ClipOval, or ClipPath, or ClipRRect etc.

I'd recommend looking through the painting and layout sections of the flutter widget catalog (and the rest of it as well) as it generally does a pretty good job of showcasing the widgets you need.

like image 109
rmtmckenzie Avatar answered Sep 25 '22 08:09

rmtmckenzie


I think it's easier to use clipBehavior: property in container

Container(
clipBehavior: Clip.hardEdge,
height: 400,
width: 400,
child :TheTransformingChild(),)
like image 22
Shakthi Hettiarachchi Avatar answered Sep 23 '22 08:09

Shakthi Hettiarachchi