Home > Software design >  My endDrawer with custom icon it is not openning on pressed
My endDrawer with custom icon it is not openning on pressed

Time:11-30

I've been suffering because I would like an END DRAWER WITH CUSTON ICON in another hand I have my endDrawer with custon Icon but on pressed stop working. What may i change on my code and back to work ? Thanks for all


  @override
  Widget build(BuildContext context) {
          final GlobalKey<ScaffoldState> _key = GlobalKey(); 
    return Scaffold(
      drawerEnableOpenDragGesture: true,
      appBar: AppBar(
      
        title: Text('Relatório'),
        actions: <Widget>[
            IconButton(
              icon: Icon(Icons.filter_list_outlined),
               onPressed: () => _key.currentState?.openEndDrawer(), 
            ),
          ],
          
      ),
      endDrawer: Drawer(
        key: _key,
        child: Container(
          width: 100,
          height: 100,
        ),
      ),
    );
  }



As you guys can see my code is not responding as expected. give me suggestions.

CodePudding user response:

You need to provide the key on Scaffold instead of Drawer widget.

   return Scaffold(
      key: _key,
 Widget build(BuildContext context) {
    final GlobalKey<ScaffoldState> _key = GlobalKey();
    return Scaffold(
      key: _key,
      drawerEnableOpenDragGesture: true,
      appBar: AppBar(
        title: Text('Relatório'),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.filter_list_outlined),
            onPressed: () => _key.currentState?.openEndDrawer(),
          ),
        ],
      ),
      endDrawer: Drawer( //not here 
        child: Container(
          width: 100,
          height: 100,
        ),
      ),
    );
  }
  • Related