medyas / flutter_zoom_drawer

A Flutter package with custom implementation of Drawer
MIT License
457 stars 102 forks source link

ZoomDrawer.of(context) returns null #112

Closed AgustinV08 closed 2 years ago

AgustinV08 commented 2 years ago

When using this package and trying to implement the Zoom Drawer class and toggle the state with a button, the static function returns null.

Here's my code

@override
  Widget build(BuildContext context)
  {
    return ZoomDrawer(
      menuScreen: const LeasyMenuScreen(),
      mainScreen: Scaffold(
        appBar: AppBar(
          leading: IconButton(
            onPressed: ()
            {
              ZoomDrawer.of(context)!.isOpen();
            },
            icon: const Icon(Icons.menu),
          ),
        ),
        body: SafeArea(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: const [
              Text('Home Page'),
            ],
          ),
        ),
      ),
    );
  }
medyas commented 2 years ago

@AgustinV08 Wrap your IconButton with a Builder widget, and use the builder context to access the ZoomDrawer