如何在 endDrawer 关闭后 运行 起作用

How to run function when after endDrawer is closed in flutter

我有产品列表页面,我从中打开了包含购物车项目的 endDrawer。如果我删除购物车项目,它不会自动更新产品列表页面。如何在 flutter 的 endDrawer 中使用 .then 函数?

不幸的是,你不能只用 DrawerController 包裹你的末端抽屉并在它关闭或打开时获得回调,因为 Scaffold 确实为它自己制作了一个抽屉控制器并封装它所以你不能修改它。

我能想到的唯一其他方法是将抽屉控制器放在主脚手架之外,或者如果您熟悉这些,则使用 Overlay 显示它。

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,
            ),
          ),
        ],
      ),
    );
  }
}