Flutter align button to bottom of Drawer

后端 未结 6 673
慢半拍i
慢半拍i 2021-02-03 21:29

I\'m trying to have a Widget align to the bottom of my NavDrawer while still keeping a DrawerHeader and a list at the top of the Drawer. Here\'s what I\'m trying:



        
6条回答
  •  名媛妹妹
    2021-02-03 22:24

    A little late to the party, but here's my solution to this problem:

      @override
      Widget build(BuildContext context) {
        return Drawer(
          // column holds all the widgets in the drawer
          child: Column(
            children: [
              Expanded(
                // ListView contains a group of widgets that scroll inside the drawer
                child: ListView(
                  children: [
                    UserAccountsDrawerHeader(),
                    Text('In list view'),
                    Text('In list view too'),
                  ],
                ),
              ),
              // This container holds the align
              Container(
                  // This align moves the children to the bottom
                  child: Align(
                      alignment: FractionalOffset.bottomCenter,
                      // This container holds all the children that will be aligned
                      // on the bottom and should not scroll with the above ListView
                      child: Container(
                          child: Column(
                        children: [
                          Divider(),
                          ListTile(
                              leading: Icon(Icons.settings),
                              title: Text('Settings')),
                          ListTile(
                              leading: Icon(Icons.help),
                              title: Text('Help and Feedback'))
                        ],
                      )
                    )
                  )
                )
            ],
          ),
        );
      }
    

    This produces the below output where the UserAccountDrawerHeader and the text items can be scrolled around inside the drawer but the Divider and the two ListTiles stay static on the bottom of the drawer.

提交回复
热议问题