I have one constraint widget in center of screen so i want to add new widget which is above of center widget.
I have added red box in center of the screen and i want to place blue box above of red box.
I have tried with constraint and column widget in stack widget but new widget not set on above of center widget.
body: Container(
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: [
Container(
height: 150,
width: 100,
color: Colors.blue,
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 100,
width: 200,
color: Colors.red,
)
],
)
],
),
),
3
Answers
To center a blue box above a red box, use a
Column
withMainAxisAlignment.center
andCrossAxisAlignment.center
. Here’s the updated code:I Hope this may help you
To place a widget above the center widget, you can use the Stack widget to layer your widgets. Here’s a simple example based on your code:
Example