简体   繁体   English

Flutter:抽屉内将 ListTile 项目移至底部

[英]Flutter: Inside Drawer move ListTile Items to Bottom

Inside the 2nd Container where the Text Account and Logout is located, i'd like that this is at the Bottom of the Drawer.在文本帐户和注销所在的第二个容器内,我希望它位于抽屉的底部。 I Added the Widget Align and alignment:bottomCenter, but this doesn't work.我添加了小部件对齐和 alignment:bottomCenter,但这不起作用。 I also tried is with FractionalOffset but this doesn't work aswell.我也尝试过使用 FractionalOffset 但这也不起作用。

What mistake am i making here that the Container is not moved to the Bottom?我在这里犯了什么错误,容器没有移到底部?

Code代码

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mealapp/models/global.dart';
import 'package:mealapp/screens/meal_plan/meal_plan.dart';
import 'package:mealapp/screens/shopping_plan/shopping.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mealapp/bloc/auth/auth_bloc.dart';
import 'package:mealapp/bloc/auth/auth_event.dart';

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.white,
      statusBarBrightness: Brightness.light,
      statusBarIconBrightness: Brightness.dark,
    ));
    final authBloc = context.bloc<AuthBloc>();

    return DefaultTabController(
      length: 2,
      child: Scaffold(
        key: _scaffoldKey,
        drawer: Theme(
          data: Theme.of(context).copyWith(canvasColor: darkGreyColor),
          child: Drawer(
            child: ListView(
              padding: EdgeInsets.zero,
              children: <Widget>[
                DrawerHeader(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(20),
                  ),
                  child: Center(
                    child: Text(
                      'Settings',
                      style: darkTodoTitle,
                    ),
                  ),
                ),
                ListTile(
                  leading:
                      Icon(Icons.create, color: Colors.white, size: 25),
                  onTap: () {},
                  title: Text(
                    'Create New List',
                    style: TextStyle(color: Colors.white, fontSize: 20),
                  ),
                ),
                Container(
                  child: Column(
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Padding(
                              padding: EdgeInsets.symmetric(horizontal: 10.0),
                              child: Container(
                                height: 1.8,
                                color: Colors.white54,
                              ),
                            ),
                          ),
                        ],
                      ),
                      ListTile(
                        leading: Icon(Icons.account_box,
                            color: Colors.white, size: 25),
                        onTap: () {},
                        title: Text(
                          'Here the Lists you got access or created',
                          style: TextStyle(color: Colors.white, fontSize: 20),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                 child: Align(alignment: Alignment.bottomCenter,
                  child: Column(
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Padding(
                              padding: EdgeInsets.symmetric(horizontal: 10.0),
                              child: Container(
                                height: 1.8,
                                color: Colors.white54,
                              ),
                            ),
                          ),
                        ],
                      ),
                      ListTile(
                        leading: Icon(Icons.account_box,
                            color: Colors.white, size: 25),
                        onTap: () {},
                        title: Text(
                          'Account',
                          style: TextStyle(color: Colors.white, fontSize: 20),
                        ),
                      ),
                      ListTile(
                        leading:
                            Icon(Icons.person, color: Colors.white, size: 25),
                        onTap: () => authBloc.add(LogoutUser()),
                        title: Text(
                          'Logout',
                          style: TextStyle(color: Colors.white, fontSize: 20),
                        ),
                      ),
                    ],
                  ),
                ),
                ),
              ],
            ),
          ),
        ),
        appBar: AppBar(
          brightness: Brightness.light,
          elevation: 0,
          leading: Builder(
            builder: (context) => IconButton(
                onPressed: () => _scaffoldKey.currentState.openDrawer(),
                icon: Icon(
                  Icons.menu,
                  color: Colors.blue,
                )),
          ),
          title: TabBar(
            tabs: [
              Tab(
                icon: Icon(Icons.fastfood),
              ),
              Tab(
                icon: Icon(Icons.local_grocery_store),
              ),
            ],
            labelColor: darkGreyColor,
            unselectedLabelColor: Colors.blue,
            indicatorSize: TabBarIndicatorSize.label,
            indicatorPadding: EdgeInsets.all(5.0),
            indicatorColor: Colors.transparent,
          ),
          backgroundColor: Colors.white,
        ),
        body: TabBarView(
          children: [
            MealPage(),
            ShoppingPage(),
          ],
        ),
        backgroundColor: Colors.white,
      ),
    );
  }
}

You need to wrap ListTile Widget inside Align Widget and provide alignment: FractionalOffset.bottomCenter .您需要将ListTile Widget 包装在Align Widget 中并提供alignment: FractionalOffset.bottomCenter This Align Widget should be wrapped with Expanded Widget as you mentioned in the question you missed to wrap Align inside Expanded Widget.正如您在错过将Align包装在Expanded Widget 内的问题中提到的那样,此Align Widget 应该用Expanded Widget 包装。 Try as follows this will help you.请尝试以下操作,这将对您有所帮助。

Expanded(
    child: Align(
         alignment: FractionalOffset.bottomCenter,
         child: ListTile(
             leading: Icon(Icons.account_box,
             color: Colors.white, size: 25),
             onTap: () {},
                 title: Text(
                 'Account',
                  style: TextStyle(
                      color: Colors.white, fontSize: 20
                  ),
              ),
          ),
      ),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM