我有一个产品列表页面,从中打开了包含购物车项目的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,
),
),
],
),
);
}
}