Im trying to implement the ui as below. i have tried with stack with two containers , with one positioned.
but the result is like this
what is the correct way to achieve this ?
4
Give the stack some additional space to prevent the overlapped container from getting clipped:
Here’s the code:
Container( width: 300, height: 350, child: Stack( children: [ Container( width: 300 , height: 300, color: Colors.orange, ), Positioned( bottom: 0, left: 50, child: Container( width : 200, height: 100, color: Colors.red, ), ) ], ) )
it’s Math, Stack is represented in 350px of height while:
remaining = 50px
You can wrap your stack in a sizedbox of height more than your large container.
SizedBox( height: 200, child: Stack( alignment: Alignment.center, children: [ Container( height: 160, width: 250, color: Colors.yellow, ), Positioned( bottom: -2, child: Container( width: 80, height: 40, color: Colors.red, alignment: Alignment.center, child: const Text("Back"), ), ) ], ), )
You can refer to the above code to get the desired approach. Hope it helps.
There is property in stack called clipBehavior by default it is set as Clip.hardEdge meaning it will clip any overflowing part from the widget.
clipBehavior
Clip.hardEdge
you can set it as Clip.none and also mind the parent size of Stack. So that it does not overflow over other widgets
Clip.none
This is how I would do it:
SizedBox( width: 300, height: 400, child: Stack( children: [ Container( margin: const EdgeInsets.only(bottom: 18), decoration: BoxDecoration( color: Colors.orange[300], borderRadius: BorderRadius.circular(20), ), ), Align( alignment: Alignment.bottomCenter, child: ElevatedButton( onPressed: () {}, style: ElevatedButton.styleFrom( backgroundColor: Colors.red[500], padding: const EdgeInsets.symmetric(horizontal: 32), ), child: const Text( "Back", style: TextStyle( color: Colors.white, ), ), ), ), ], ), );
Result:
Click here to cancel reply.
4
Answers
Give the stack some additional space to prevent the overlapped container from getting clipped:
Here’s the code:
it’s Math, Stack is represented in 350px of height while:
other 50px will be above the first child.
You can wrap your stack in a sizedbox of height more than your large container.
You can refer to the above code to get the desired approach. Hope it helps.
There is property in stack called
clipBehavior
by default it is set asClip.hardEdge
meaning it will clip any overflowing part from the widget.you can set it as
Clip.none
and also mind the parent size of Stack. So that it does not overflow over other widgetsThis is how I would do it:
Result: