flutter 删除抽屉标题中的多余空间

xzlaal3s  于 2023-04-05  发布在  Flutter
关注(0)|答案(2)|浏览(192)

我要实现此抽屉标题

但是我的抽屉有很大的空间,如何去除抽屉顶部多余的空间?

编码

class AppDrawer extends HookWidget {
  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          _createHeader(),
          _createDrawerItem(
            icon: Icons.contacts,
            text: 'Contacts',
            onTap: () {},
          ),
          _createDrawerItem(
            icon: Icons.event,
            text: 'Events',
            onTap: () {},
          ),
        ],
      ),
    );
  }

  Widget _createDrawerItem(
      {required IconData icon,
      required String text,
      required GestureTapCallback onTap}) {
    return ListTile(
      title: Row(
        children: <Widget>[
          Icon(icon),
          Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child: Text(text),
          )
        ],
      ),
      onTap: onTap,
    );
  }

  Widget _createHeader() {
    return const DrawerHeader(
        decoration: BoxDecoration(color: Colors.green),
        child: ListTile(
          title: Text("Name"),
          subtitle: Text("Email"),
          dense: true,
          leading: CircleAvatar(child: Icon(Icons.people)),
        ));
  }
}

忽略此行epfokeofkpekf efewfefefefefefefefefewf fewfef fefef fefjoej jifjeojfo oijoewfjoej oijfoijfoiejf rvw

nvbavucw

nvbavucw1#

除了DrawerHeader,您还可以使用Container或SizedBox来根据需要更改其高度。

hgtggwj0

hgtggwj02#

你可以使用Container()来代替DrawerHeader()
示例:

class AppDrawer extends HookWidget {
  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          _createHeader(),
          _createDrawerItem(
            icon: Icons.contacts,
            text: 'Contacts',
            onTap: () {},
          ),
          _createDrawerItem(
            icon: Icons.event,
            text: 'Events',
            onTap: () {},
          ),
        ],
      ),
    );
  }

  Widget _createDrawerItem(
      {required IconData icon,
      required String text,
      required GestureTapCallback onTap}) {
    return ListTile(
      title: Row(
        children: <Widget>[
          Icon(icon),
          Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child: Text(text),
          )
        ],
      ),
      onTap: onTap,
    );
  }

  Widget _createHeader() {
    return Container(
        height: 100,
        decoration: BoxDecoration(color: Colors.green),
        child: ListTile(
          title: Text("Name"),
          subtitle: Text("Email"),
          dense: true,
          leading: CircleAvatar(child: Icon(Icons.people)),
        ));
  }
}

相关问题