How to align a Column's child to the bottom

后端 未结 4 2289
后悔当初
后悔当初 2021-02-18 14:30

I\'m trying to build a generic home page and I want to align the last child of my column (which contains all the widgets for the page) to the bottom of the screen but the widget

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-18 15:08

    You can use Expanded to make the last widget expand to the whole remaining space.

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'My Layout',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            title: new Text("Align Bottom Demo"),
          ),
          body: new Column(children: [
            new Text("Text 1"),
            new Text("Text 2"),
            new Expanded(
                child: new Align(
                    alignment: Alignment.bottomCenter,
                    child: new Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        new Icon(Icons.star),
                        new Text("Bottom Text")
                      ],
                    )))
          ]),
        );
      }
    }
    

    Here is the result

提交回复
热议问题