Flutter: Attempts to get the bottom center of an element in a column, but it retains left alignment

I am trying to create the bottom center of the widget at the bottom of the column, but it continues to align to the left.

return new Column(
  new Stack(
    new Positioned(
      bottom: 0.0, 
      new Center(
        new Container(),
      ),
    ),
  ),
); 

The existence of a Positioned Force Container is on the left, not centering. However, the removal of the position placed in the container is placed in the middle center.

+30
source share
5 answers

Alignment is the way to go if 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
  ],
);
+53
source

1) You can use Align s widget FractionalOffset.bottomCenter.

2) left: 0.0 right: 0.0 Positioned.

+16

I used this approach,

What I want is layoutalways at the bottom, but whenever a keyboard pops up, this one layoutalso appears on top of it.

enter image description here

body: Container(
        color: Colors.amber,
        height: double.maxFinite,
        child: new Stack(
          //alignment:new Alignment(x, y)
          children: <Widget>[
            new Positioned(
              child: myWidget(context, data.iconName, Colors.red),
            ),
            new Positioned(
              child: new Align(
                alignment: FractionalOffset.bottomCenter,
                child: myWidget(context, data.iconName, Colors.green)
              ),
            )
          ],
        ),
      ),
+13
source

Wrap your container in the SingleChildScrollView () widget. Then it will not be higher when the keyboard pops up.

0
source
Expanded(
            child: Align(
              alignment: FractionalOffset.bottomCenter,
              child: Padding(
                padding: EdgeInsets.only(bottom: 10.0),
                child: //Your widget here,
              )
            ),
          )
0
source

Source: https://habr.com/ru/post/1683931/


All Articles