You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中Navigation Drawer从右侧弹出的实现求助

Flutter实现右侧弹出的Navigation Drawer

要让你的Navigation Drawer从屏幕右侧弹出,只需完成以下两处修改:

1. 设置Drawer的右侧对齐

在你的NavigationDrawerWidget中,为Drawer组件添加alignment属性,指定其从右侧对齐:

return Drawer(
  alignment: Alignment.centerRight, // 添加该行实现右侧弹出
  child: Material(
    color: Colors.white,
    child: ListView(
      children: <Widget>[
        buildHeader(
          urlImage: urlImage,
          name: name,
          email: email,
          onClicked:  () => Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => Profilepic(
              name : 'Super Admin',
              urlImage: urlImage,
            ),
          ),
        ),),
        // 原有的其他组件保持不变
      ],
    ),
  ),
);

2. 正确调用右侧抽屉

在包含抽屉的页面Scaffold中,将原来的drawer属性替换为endDrawer,或者在触发抽屉打开的按钮中调用openEndDrawer():

方式一:使用Scaffold的endDrawer属性

Scaffold(
  endDrawer: NavigationDrawerWidget(), // 替换原有的drawer属性
  appBar: AppBar(
    // 你的AppBar配置
  ),
  body: // 页面主体内容
)

方式二:通过按钮调用openEndDrawer()

IconButton(
  icon: Icon(Icons.menu),
  onPressed: () {
    Scaffold.of(context).openEndDrawer();
  },
)

完成以上修改后,你的Navigation Drawer就会从屏幕右侧弹出,达到你期望的效果。

内容的提问来源于stack exchange,提问作者SHAMMAS MUHAMMED

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 05:53:22