如何将 Text/ListTile 小部件(在抽屉内)放置在 phone 屏幕的最底部

How to place a Text/ListTile widget (inside Drawer) at the very bottom of the phone screen

所以我的问题很简单,但我遇到了一些麻烦。我希望我的 Text/ListTile 位于抽屉的最底部,它有点像版权声明,但问题是我不能将它放到底部,因为它总是将它放在最后一个小部件(如果有的话)下面。

image

我的代码:

const Expanded(
              child: Align(
                  alignment: FractionalOffset.bottomCenter,
                  child: ListTile(
                    title: Text(
                      'Hak Cipta \u00a9 2022 Jabatan Perikanan Malaysia',
                      style: TextStyle(color: Colors.black45, fontSize: 12),
                      textAlign: TextAlign.center,
                    ),
                  )),
            )

我听说使用 Spacer() 或 Divider() 会起作用,但那些只对某些 phone 起作用,这意味着如果我制作 Spacer/Divider(top : 300),它将显示在最底部仅适用于我的 phone 的抽屉,但不适用于与我的 phone 不同的分辨率。

完整代码:

drawer: Container(
      width: 230,
      child: Drawer(
        elevation: 0,
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.vertical(
            bottom: Radius.circular(22),
            top: Radius.circular(22),
          ),
        ),
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text(''),
              decoration: BoxDecoration(color: Colors.blue[900]),
            ),
            ListTile(
              title: const Text('Profile Pengguna'),
              onTap: () {
                Navigator.of(context).pushReplacement(MaterialPageRoute(
                    builder: (context) =>
                        HomePage(username: widget.username2)));
              },
            ),
            ListTile(
              title: const Text('Senarai Kursus'),
              onTap: () {
                Navigator.of(context).pushReplacement(MaterialPageRoute(
                    builder: (context) =>
                        KursusList(username: widget.username2)));
              },
            ),
            ListTile(
              title: const Text('Transaksi Kursus'),
              onTap: () {
                Navigator.of(context).pushReplacement(MaterialPageRoute(
                    builder: (context) =>
                        TransaksiKursus(username: widget.username2)));
              },
            ),
            ListTile(
              title: const Text('Log Keluar'),
              onTap: () {
                Navigator.of(context).pushAndRemoveUntil(
                    MaterialPageRoute(builder: (context) => LoginDemo()),
                    (Route route) => false);
              },
            ),
            const Spacer(),
            const Expanded(
              child: Align(
                  alignment: FractionalOffset.bottomCenter,
                  child: ListTile(
                    dense: true,
                    visualDensity: VisualDensity(vertical: -4),
                    title: Text(
                      'Hak Cipta \u00a9 2022 Jabatan Perikanan Malaysia',
                      style: TextStyle(color: Colors.black45, fontSize: 12),
                      textAlign: TextAlign.center,
                    ),
                  )),
            )
          ],
        ),
      ),
    ),

我在调试控制台中也收到了 Incorrect use of ParentDataWidget. 。我不知道这是否与我现在遇到的问题有关,但值得一提

试试这个:-

const Expanded(
          child: SizedBox(),
        ),
ListTile(
    title: Text(
    Hak Cipta \u00a9 2022 Jabatan Perikanan Malaysia',
    style: TextStyle(color: Colors.black45, fontSize: 12),
    textAlign: TextAlign.center,
                    ),

在包含 child:Column() 和参数 CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.center.

的抽屉中制作小部件

使用扩展

    drawer:  Drawer(
        
        // Add a ListView to the drawer. This ensures the user can scroll
        // through the options in the drawer if there isn't enough vertical
        // space to fit everything.
                  child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        Expanded(
                            child: ListView(
        
                                padding: EdgeInsets.zero,
                                children: <Widget>[
                                  ListTile(
                                    title: Row(
                                      children: <Widget>[
                                        Padding(
                                          padding: EdgeInsets.only(left: 0.0),
                                          child: Text("text1"),
                                        )
                                      ],
                                    ),
        
                                  )
                                ]
                            )
                        ),
                        Container(
                          color: Colors.red,
        
                          padding: EdgeInsets.all(10.0),
                          child:
        
        
                          Row (
                            mainAxisSize: MainAxisSize.max,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
        
                            children : <Widget> [
        
        
                              Text(" Hak Cipta \u00a9 2022 Jabatan Perikanan Malaysia"
                              )
        
                            ]
        
        
        
                            ,
                          ),
        
        
                        )
                     

 ])),

试试下面的代码,我想从你的代码中删除 Spacer。在我的代码中添加您的额外代码

drawer: Container(
    width: 250,
    child: Drawer(
      //drawer Code
      child: Column(
        children: <Widget>[
          ListTile(
            hoverColor: Colors.blue,
            dense: true,
            visualDensity: VisualDensity(vertical: -4),
            title: Text('Profile Pengguna'),
            onTap: () {},
          ),
          Divider(
            color: Colors.grey,
          ),
          ListTile(
            dense: true,
            visualDensity: VisualDensity(vertical: -4),
            title: Text('Senarai Kursus'),
            onTap: () {},
          ),
          Divider(
            color: Colors.grey,
          ),
          ListTile(
            dense: true,
            visualDensity: VisualDensity(vertical: -4),
            title: Text('Transaksi Kursus'),
            onTap: () {},
          ),
          Divider(
            color: Colors.grey,
          ),
          ListTile(
            dense: true,
            visualDensity: VisualDensity(vertical: -4),
            title: Text('Log Keluar'),
            onTap: () {},
          ),
          Divider(
            color: Colors.grey,
          ),
          Expanded(
            child: Align(
              alignment: FractionalOffset.bottomCenter,
              child: ListTile(
                dense: true,
                visualDensity: VisualDensity(vertical: -4),
                title: Text(
                  'Hak Cipta \u00a9 2022 Jabatan Perikanan Malaysia',
                  style: TextStyle(color: Colors.black45, fontSize: 12),
                  textAlign: TextAlign.center,
                ),
                onTap: () {},
              ),
            ),
          ),
        ],
      ),
    ),
  ),

结果屏幕->

也参考回答