I want my container to have different size depending on their content (in this case a text), if one user write a longer text the container will be biger and if another user write a shorter text the container will be smaller.
Is it possible? And if not is there another way to do it?
Thanks
This is what I want to achieve (it's a screenshot of Samsung note app)
You need to not assign
width
orheight
to theContainer
so it will resize depending on thechild
:If you want to control max width and max height you will use
Container
'sconstraints
fieldAnd of course you can give it
minWidth
andminHeight
inBoxConstraints
.Result when you are under
maxWidth
Result when you have text so long that it goes over the bounds of
maxWidth
, in this case height resizes automatically:You can also add padding for better look:
But for other types of widgets, other than
Text
it will be much safer if you wrap them withFittedBox
like this, notice theText
widget :