可能有更好的方法,但这是我的做法。
这是包含抽屉的主仪表板
return Scaffold(
drawer: Drawer(
key: Key("dash_board_screen_key"),
child: menu(context: context, model: model),
),
appBar: AppBar(
title: Text(
model.getTitle(),
),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(
Icons.lightbulb_outline,
size: 18,
),
onPressed: () {
model.toggleDarkMode();
}),
],
),
body: Padding(
padding: EdgeInsets.only(left: 20.w, right: 20.w),
child: Expanded(child: getDashboardWidget(model)),
) // dashboard(context),
);
正如您在上面看到的,getDashboardWidget 返回一个显示的小部件
Widget getDashboardWidget(DashboardController model){
switch (model.selectedItem) {
case DashboardMenu.cart:
return CartScreen();
case DashboardMenu.notification:
return NotificationScreen();
case DashboardMenu.profile:
return ProfileScreen();
}
return CartScreen();
}
所以根据选择的抽屉选项,我只更新了仪表板页面的正文。
这意味着所有其他屏幕(CartScreen、Notification)共享同一个脚手架。