-1

I have product list page from which i opened endDrawer which contains cart item. if i remove cart items it does not update the product list page automatically. how to use .then function in endDrawer in flutter?

B.Ayaz
  • 47
  • 1
  • 9

1 Answers1

1

Unfortunately you can't just Wrap your end drawer with a DrawerController and get callbacks when it is closed or opened, because Scaffold does make a drawer controller for it self and encapsulates it so you can not modify it.

The only other way I can think of is putting the drawer controller outside your main scaffold or showing it using Overlay if you are familiar with those.

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned.fill(
            child: Scaffold(
              appBar: PreferredSize(
                preferredSize: Size.fromHeight(kToolbarHeight),
                child: UserAppBar(),
              ),
              body: PostsPage(),
            ),
          ),
          Positioned.fill(
            child: DrawerController(
              child: Drawer(
                child: Column(),
              ),
              drawerCallback: (open){
                print(open);
              },
              alignment: DrawerAlignment.end,
            ),
          ),
        ],
      ),
    );
  }
}
Ali Qanbari
  • 2,923
  • 1
  • 12
  • 28
  • looks like scaffold makes a `DrawerController` automatically and you can't have them inside each other. – Ali Qanbari Jan 16 '20 at 18:14
  • you may also may want to look into state management. updating of widgets and lists should not be a problem in the first place. you can do it using streams and Blocs or any other way. I personally really like using ValueNotifiers and AnimatedBuilders. – Ali Qanbari Jan 16 '20 at 18:31