'Open drawer when using BackdropAppBar

I am using the BackdropAppBar package and would like to open the drawer programmatically from the leading icon using something like that : _scaffoldKey.currentState!.openDrawer();

But it doesn't work The drawer is visible when swiping but i want a menu icon to activate it Also tried this : Backdrop.of(context).scaffoldKey!.currentState!.openDrawer();

Heres's my code :

BackdropScaffold(
      key: _scaffoldKey,
      appBar: BackdropAppBar(
        title: Text('PRODUCTS'),
        centerTitle: true,
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.person),
            onPressed: () {
              print('open drawer');//text is printed
              //none of the following work
              _scaffoldKey.currentState!.openDrawer();
              Scaffold.of(context).openDrawer();
              Backdrop.of(context).scaffoldKey!.currentState!.openDrawer();
              } ,
          ),
          BackdropToggleButton(
            icon: AnimatedIcons.close_menu,
          ),
        ],
        drawer: MyDrawer(),
        frontLayer: pageBuilder(),
        backLayer: Center(
            child: Text("Back Layer"),
        ),

    ));
  }

_scaffoldKey is defined like this :

final GlobalKey<BackdropScaffoldState> _scaffoldKey = GlobalKey<BackdropScaffoldState>();

Here's the error :

Exception caught by gesture The following _CastError was thrown while handling a gesture: Null check operator used on a null value

When the exception was thrown, this was the stack: #0 Backdrop.of (package:backdrop/src/scaffold.dart:29:61)



Solution 1:[1]

I actually found a solution :

replace key: _scaffoldKey with scaffoldKey: _scaffoldKey

Hopefully this will save somebody some time

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zied Zrelli