Выровнять плитку списка ящиков по низу ящика

avatar
Kavishka Rajapakshe
9 августа 2021 в 04:58
407
2
2

Я создал ящик для своего приложения. Он работает нормально, но я не могу выровнять кнопку выхода по нижней части ящика. Я пробовал выравнивание виджета, это не сработало. Пробовал выравнивать виджет внутри расширенного виджета, все еще не работает. Перепробовал почти все, что смог найти. Не знаю, почему не выравнивается. Пожалуйста, помогите.

 drawer: Drawer(
    child: ListView(
      children: <Widget>[
        DrawerHeader(
          child: Align(
            alignment: Alignment.topLeft,
            child: Container(
              child: Column(
                children: [
                  CircleAvatar(
                    backgroundColor: Colors.yellow,
                    child: const Text('USER'),
                    radius: 25,
                  ),
                  Text(name),
                  Text(email)
                ],
              ),
            ),
          ),
        ),
        ListTile(
          title: Text("Settings",style:TextStyle(fontWeight: FontWeight.bold),),
          trailing: Icon(Icons.settings),
          onTap: () {
            context.read<NavCubit>().showHome();
            Navigator.pop(context);
          },
        ),
        Container(
          height: 1.0,
          width: MediaQuery.of(context).size.width,
          color: Colors.tealAccent,
        ),
        ListTile(
          title: Text("Learning",style:TextStyle(fontWeight: FontWeight.bold),),
          trailing: Icon(Icons.book),
          onTap: () {
            context.read<NavCubit>().showContracts();
          },
        ),
        Container(
          height: 1.0,
          width: MediaQuery.of(context).size.width,
          color: Colors.tealAccent,
        ),
             Align(
              alignment: Alignment.bottomCenter,
              child: ListTile(
                title: Text("Log Out",style:TextStyle(fontWeight: FontWeight.bold),),
                trailing: Icon(Icons.logout),
                onTap: () {
                  context.read<NavCubit>().showContracts();
                },
              ),
            ),
      ],
    ),
Источник

Ответы (2)

avatar
Ravindra S. Patil
9 августа 2021 в 05:14
2

См. приведенный ниже код, надеюсь, он вам поможет.

drawer: Container(
        width: 250,
        child: Drawer(
          //drawer Code
          child: Column(
            children: <Widget>[
             
              ListTile(
                hoverColor: Colors.blue,
                dense: true,
                visualDensity: VisualDensity(vertical: -4),
                leading: Icon(
                  Icons.show_chart,
                  color: Colors.black,
                ),
                title: Text('All Leads'),
                onTap: () {},
              ),
              Divider(
                color: Colors.grey,
              ),
              ListTile(
                hoverColor: Colors.blue,
                dense: true,
                visualDensity: VisualDensity(vertical: -4),
                leading: Icon(
                  Icons.bar_chart_rounded,
                  color: Colors.black,
                ),
                title: Text('Graphs'),
                onTap: () { },
              ),
              Divider(
                color: Colors.grey,
              ),
              ListTile(
                hoverColor: Colors.blue,
                dense: true,
                visualDensity: VisualDensity(vertical: -4),
                leading: Icon(
                  Icons.group,
                  color: Colors.black,
                ),
                title: Text('Agents'),
                onTap: () {},
              ),
              Divider(
                color: Colors.grey,
              ),
              ListTile(
                hoverColor: Colors.blue,
                dense: true,
                visualDensity: VisualDensity(vertical: -4),
                leading: Icon(
                  Icons.book,
                  color: Colors.black,
                ),
                title: Text('About Us'),
                onTap: () {},
              ),
              Divider(
                color: Colors.grey,
              ),
              Expanded(
                child: Align(
                  alignment: FractionalOffset.bottomCenter,
                  child: ListTile(
                    hoverColor: Colors.blue,
                    dense: true,
                    visualDensity: VisualDensity(vertical: -4),
                    leading: Icon(
                      Icons.logout,
                      color: Colors.black,
                    ),
                    title: Text('Logout'),
                    onTap: () {},
                  ),
                ),
              ),
            ],
          ),
        ),
      ),

Ваш ящик выглядит так->Your Drawer Look like this

Ravindra S. Patil
9 августа 2021 в 05:29
0

Добро пожаловать @KavishkaRajapakshe

avatar
Naveen Avidi
9 августа 2021 в 05:12
0
drawer: Drawer(
    child: ListView(
      children: <Widget>[
        DrawerHeader(
          child: Align(
            alignment: Alignment.topLeft,
            child: Container(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  CircleAvatar(
                    backgroundColor: Colors.yellow,
                    child: const Text('USER'),
                    radius: 25,
                  ),
                  Text(name),
                  Text(email)
                ],
              ),
            ),
          ),
        ),
        ListTile(
          title: Text("Settings",style:TextStyle(fontWeight: FontWeight.bold),),
          trailing: Icon(Icons.settings),
          onTap: () {
            context.read<NavCubit>().showHome();
            Navigator.pop(context);
          },
        ),
        Container(
          height: 1.0,
          width: MediaQuery.of(context).size.width,
          color: Colors.tealAccent,
        ),
        ListTile(
          title: Text("Learning",style:TextStyle(fontWeight: FontWeight.bold),),
          trailing: Icon(Icons.book),
          onTap: () {
            context.read<NavCubit>().showContracts();
          },
        ),
        //code change and use Divider widget for gap/space bw widgets rather than Container
        Expanded(
         child: Container(
          width: MediaQuery.of(context).size.width,
          color: Colors.tealAccent,
         )
        ),
        ListTile(
                title: Text("Log Out",style:TextStyle(fontWeight: FontWeight.bold),),
                trailing: Icon(Icons.logout),
                onTap: () {
                  context.read<NavCubit>().showContracts();
                },
              ),
      ],
    ),