I\'m trying to bottom-center a widget at the bottom of a Column, but it keeps aligning to the left.
return new Column(
new Stack(
new Positioned(
Align is the way to go is you have only one child.
If you have more, consider doing something like this :
return new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
//your elements here
],
);
In addition of Stack: to avoid floating container on keyboard, use this
return Scaffold(
appBar: getAppBar(title),
resizeToAvoidBottomInset: false,
body:
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: 10.0),
child: //Your widget here,
),
),
),
If you wish to leave content as it, can wrap it with scrollable.
Useful if you have inputs in the children:
return Stack(
children: <Widget>[
Positioned(
child: SingleChildScrollView(
child: Column(
children: children
..add(Container(
height: 56, // button heigh, so could scroll underlapping area
)))),
),
Positioned(
child: Align(
alignment: Alignment.bottomCenter,
child: button,
),
)
],
);
To do this easily, the use of Stack
is better. Create a Stack
Then inside Stack add Align
or Positioned
and set position according to your needed, You can add multiple Container
.
Container
child: Stack(
children: <Widget>[
Align(
alignment: FractionalOffset.center,
child: Text(
"₹ 1000",
)
),
Positioned(
bottom: 0,
child: Container(
width: double.infinity,
height: 30,
child: Text(
"Balance", ,
)
),
)
],
)
)
Stack
a widget that positions its children relative to the edges of its box.
Stack
class is useful if you want to overlap several children in a simple way, for example having some text and an image, overlaid with a gradient and a button attached to the bottom.
Just expanding the answers:
Positioned
/ Align
.Stack
Stack
directly.