在endDrawer中关闭后如何运行功能

问题描述 投票:0回答:1

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

flutter dynamic widget drawer scaffold
1个回答
0
投票

[不幸的是,您不能只用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,
            ),
          ),
        ],
      ),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.