1

I trying make a button for open my drawer, but i can't, this my first time using flutter

my running ui

Flutter UI

  return Scaffold(

  drawer: Drawer(),
  body: Column(
    children: <Widget>[
      ClipPath(
        clipper: MyClipper(),
        child: Container(
          height: 350,
          width: double.infinity,
          decoration: BoxDecoration(
            gradient: LinearGradient(
                begin: Alignment.topRight,
                end: Alignment.bottomLeft,
                colors: [
                  Color(0xFF3383CD),
                  Color(0xFF11429F),
                ]),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              const SizedBox(height: 12),
              IconButton(
                icon: const Icon(
                  Icons.add, size: 18,
                  color: Colors.white,
                  ),
                onPressed: () {
                  Scaffold.of(context).openDrawer();
                },
              ),
Mariano Zorrilla
  • 7,165
  • 2
  • 34
  • 52
  • 3
    Does this answer your question? [Open drawer on clicking AppBar](https://stackoverflow.com/questions/47435231/open-drawer-on-clicking-appbar) – Vitor Aug 26 '20 at 18:23

1 Answers1

6

The best way to do this is using GlobalKey.

  1. Define a GlobalKey for ScaffoldState for your widget.

    GlobalKey<ScaffoldState> scaffolKey = GlobalKey<ScaffoldState>();

  2. Assign this key to the Scaffold.

Scaffold( key: scaffoldKey, ....)

  1. Call Opendrawer using this key from the button's onPressed call.

FlatButton(onPressed: () { scaffoldKey.currentState.openDrawer(); })

theCaptainXgod
  • 223
  • 1
  • 7