Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Drawer not show up at SliverAppBar

I want to add a Drawer inside my SliverAppBar my code doesn’t have any error inside but when I run the code the drawer does not show up.

Here’s my code

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,
          );
        },
      ),

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Please have a look here.

In your Scaffold, you have to register a drawer

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

With onPressed you send the request to open the Drawer to the Scaffold:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading