Flutter: Trying to bottom-center an item in a Column, but it keeps left-aligning

后端 未结 11 2135
广开言路
广开言路 2020-12-07 18:54

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(
              


        
相关标签:
11条回答
  • 2020-12-07 19:04

    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
      ],
    );
    
    0 讨论(0)
  • 2020-12-07 19:07

    In addition of Stack: to avoid floating container on keyboard, use this

    return Scaffold(
        appBar: getAppBar(title),
        resizeToAvoidBottomInset: false,
        body:
    
    0 讨论(0)
  • 2020-12-07 19:10
    Expanded(
      child: Align(
        alignment: FractionalOffset.bottomCenter,
          child: Padding(
            padding: EdgeInsets.only(bottom: 10.0),
              child: //Your widget here,
        ),
      ),
    ),
    
    0 讨论(0)
  • 2020-12-07 19:13

    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,
              ),
            )
          ],
        );
    
    0 讨论(0)
  • 2020-12-07 19:13

    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.

    0 讨论(0)
  • 2020-12-07 19:17

    Just expanding the answers:

    • Spacer is an option no one mentioned yet; it is used in case you prefer not to use Positioned / Align.
    • Align works if you want to specify the alignment of a child inside a parent. Use it anywhere but directly inside Stack
    • Positioned is similar to Align, but works only under Stack directly.
    0 讨论(0)
提交回复
热议问题