Flutter align button to bottom of Drawer

后端 未结 6 589
慢半拍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:12

    I'd put it in a row and align all the stuff to bottom using crossAxisAlignment: CrossAxisAlignment.baseline

    Row(
                  mainAxisSize: MainAxisSize.max,
                  crossAxisAlignment: CrossAxisAlignment.baseline,
                  children: <Widget>[
                    Text(
                      '12.00',
                      style: Theme.of(context).textTheme.headline2,
                      textAlign: TextAlign.start,
                    ),
                    Text(
                      'USD',
                      style: Theme.of(context).textTheme.bodyText2,
                      textAlign: TextAlign.start,
                    ),
                  ]),
    
    0 讨论(0)
  • 2021-02-03 22:22

    A simple approach would be to use Spacer() like:

    Scaffold(
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            Text('Top'),
            Spacer(), // use this
            Text('Bottom'),
          ],
        ),
      )
    )
    
    0 讨论(0)
  • 2021-02-03 22:23

    here is my solution of a vertical Row with icons in the end of the drawer.

    @override
      Widget build(BuildContext context) {
        return Drawer(
          child: Column(
            children: <Widget>[
              Expanded(
                child: ListView(
                  children: <Widget>[
                    DrawerHeader(
                      padding: const EdgeInsets.all(7),
                      decoration: BoxDecoration(
                        color: AppColors.menuHeaderColor,
                      ),
                      child: buildHeader(),
                    ),
                    AccountDrawerRow(),
                    ListTile(
                      leading: Icon(Icons.directions_car),
                      title: Text(translations.button.vehicles),
                    ),
                    ListTile(
                      leading: Icon(Icons.calendar_today),
                      title: Text(translations.button.appointments,),
                    ),
                  ],
                ),
              ),
              Container(
                child: Align(
                  alignment: FractionalOffset.bottomCenter,
                  child: Container(
                    padding: EdgeInsets.all(15.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        InkWell(
                            onTap: () => Navigator.of(context).push(MaterialPageRoute(
                                builder: (context) => SettingsPage())),
                            child: Icon(Icons.settings)),
                        Icon(Icons.help),
                        Icon(Icons.info),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      }
    
    0 讨论(0)
  • 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: <Widget>[
              Expanded(
                // ListView contains a group of widgets that scroll inside the drawer
                child: ListView(
                  children: <Widget>[
                    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: <Widget>[
                          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.

    0 讨论(0)
  • 2021-02-03 22:28

    look whats the problem with your code you have added a Column as a Child to the Drawer so whatever you add in it are vertically placed and The height of Column is by default shrunk to its children's height and it gets larger as the child gets, so there's no point in adding an Align inside a Column

    The Simpler Solution Would be to use an Expanded Widget that takes the remaining Space Look I have used a Column and added A widget above and below the Expanded Widget.

          Drawer(
                elevation: 1.5,
                child: Column(children: <Widget>[
                  DrawerHeader(
                      decoration: BoxDecoration(
                    color: Colors.redAccent,
                  )),
                  Expanded(
                      child: ListView(
                    padding: EdgeInsets.zero,
                    children: <Widget>[
                      ListTile(
                        title: Text('My Cart'),
                        leading: Icon(Icons.shopping_cart),
                        onTap: () {},
                      ),
                      ListTile(
                        title: Text('My Orders'),
                        leading: Icon(Icons.add_shopping_cart),
                        onTap: () {},
                      ),
                      ListTile(
                          title: Text('Logout'),
                          leading: Icon(Icons.exit_to_app),
                          onTap: () {})
                    ],
                  )),
                  Container(
                    color: Colors.black,
                    width: double.infinity,
                    height: 0.1,
                  ),
                  Container(
                      padding: EdgeInsets.all(10),
                      height: 100,
                      child: Text("V1.0.0",style: TextStyle(fontWeight: FontWeight.bold),)),
                ])),
    

    0 讨论(0)
  • 2021-02-03 22:35

    You need to wrap your Align widget in Expanded.

    drawer: Drawer(
      child: Column(
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          Text('Top'),
          Expanded(
            child: Align(
              alignment: Alignment.bottomCenter,
              child: Text('Bottom'),
            ),
          ),
        ],
      ),
    ),
    
    0 讨论(0)
提交回复
热议问题