抽屉没有出现在 SliverAppBar

Drawer not show up at SliverAppBar

我想在我的 SliverAppBar 中添加一个 Drawer 我的代码里面没有任何错误但是当我 运行 代码时抽屉没有显示。

这是我的代码

body: CustomScrollView(
    slivers: <Widget>[
      SliverLayoutBuilder(
        builder: (BuildContext context, constraints) {
          final scrolled = constraints.scrollOffset > 50;
          final scrolledicon = constraints.scrollOffset > 0;

          return SliverAppBar(
            expandedHeight: 20,
            toolbarHeight: 65,
            leading: Padding(
              padding: const EdgeInsets.only(top: 2),
              child: Icon(DBIcons.logo, color: Colors.red, size: 50),
            ),
            actions: [
              Padding(
                padding: const EdgeInsets.all(10),
                child: IconButton(
                  icon: Icon(Icons.menu),
                  color: scrolledicon ? Colors.white : Colors.black,
                  onPressed: (){
                    Drawer(
                      child: Center(
                        child: Text('This is Drawer'),
                      ),
                    );
                  },
                ),
              ),
            ],
            backgroundColor: scrolled ? Colors.black : Colors.transparent,
            elevation: 0,
            pinned: true,
          );
        },
      ),

请看.

在你的脚手架中,你必须注册一个抽屉

Scaffold(
    ...
    drawer: Drawer(child: Center(
                    child: Text('This is Drawer'),
    ),
    ...
  );

使用 onPressed 您将打开抽屉的请求发送到脚手架:

onPressed: () => Scaffold.of(context).openDrawer(),