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

后端 未结 11 2162
广开言路
广开言路 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:18

    The easiest and the correct way to do it - use Spacer()

    Example:

    Column(
        children: [
          SomeWidgetOnTheTop(),
          Spacer(),
          SomeCenterredBottomWidget(),
        ],
    );
    
    0 讨论(0)
  • 2020-12-07 19:19

    Wrap your Container in SingleChildScrollView() widget. Then it will not come above when keyboard pops up.

    0 讨论(0)
  • 2020-12-07 19:20
    Widget _bottom() {
        return Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Expanded(
              child: Container(
                color: Colors.amberAccent,
                width: double.infinity,
                child: SingleChildScrollView(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: new List<int>.generate(50, (index) => index + 1)
                        .map((item) {
                      return Text(
                        item.toString(),
                        style: TextStyle(fontSize: 20),
                      );
                    }).toList(),
                  ),
                ),
              ),
            ),
            Container(
              color: Colors.blue,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'BoTToM',
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 33),
                  ),
                ],
              ),
            ),
          ],
        );
      }
    
    0 讨论(0)
  • 2020-12-07 19:22

    1) You can use an Align widget, with FractionalOffset.bottomCenter.

    2) You can also set left: 0.0 and right: 0.0 in the Positioned.

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

    I have used this approach,

    What i want is, A layout always in bottom but whenever Keyboard pops-up that layout also comes over it

    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)
                  ),
                )
              ],
            ),
          ),
    
    0 讨论(0)
提交回复
热议问题