【问题标题】:How to disable drawer button in flutter如何在颤动中禁用抽屉按钮
【发布时间】:2023-03-10 18:28:02
【问题描述】:

所以我有一个带有这个应用栏的应用,它有这个按钮。当用户按下按钮时,它会打开抽屉。但是,当您向左滑动时,它也会打开抽屉。

这是图片:The Button

这是我的代码:

return Scaffold(
      appBar: AppBar(
        title: Text(
          "AppBar",
          style: TextStyle(
              fontSize: 30,
              fontWeight: FontWeight.bold,
              fontFamily: "FjallaOne"),
        ),
        backgroundColor: Color(0xFFF0D5EAF),
      ),
      body: Container(
        child: ScrollView(),
      ),
      drawer: Drawer(
        child: ListView(
          children: [
            Text(
              "Hello world",
              style: TextStyle(
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
    );

如何禁用按钮?我只想让用户向左滑动,但屏幕上没有显示按钮。

感谢任何答案,谢谢!

【问题讨论】:

  • AppBarautomaticallyImplyLeading设置为false
  • @rickimaru,谢谢!它就像一个魅力

标签: android flutter dart flutter-layout


【解决方案1】:

您可以通过将automaticallyImplyLeading 属性设置为false 来隐藏AppBars 前导

automaticallyImplyLeading: false

基于您的代码的完整示例


return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        title: Text(
          "AppBar",
          style: TextStyle(
              fontSize: 30,
              fontWeight: FontWeight.bold,
              fontFamily: "FjallaOne"),
        ),
        backgroundColor: Color(0xFFF0D5EAF),
      ),
      body: Container(
        child: ScrollView(),
      ),
      drawer: Drawer(
        child: ListView(
          children: [
            Text(
              "Hello world",
              style: TextStyle(
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
    );

【讨论】:

    【解决方案2】:

    案例 1:如果您想要该按钮但仍不希望在该按钮上发生任何事情

     return Scaffold(
          appBar: AppBar(
            title: Text(
              "AppBar",
              style: TextStyle(
                  fontSize: 30,
                  fontWeight: FontWeight.bold,
                  fontFamily: "FjallaOne"),
            ),
            leading: IconButton(
              icon: const Icon(Icons.menu),
              onPressed: () {},
            ),
            backgroundColor: Color(0xFFF0D5EAF),
          ),
          body: Container(
            child: Container(),
          ),
          drawer: Drawer(
            child: ListView(
              children: [
                Text(
                  "Hello world",
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
        );
    

    案例 2:如果您根本不需要按钮

    return Scaffold(
              appBar: AppBar(
                title: Text(
                  "AppBar",
                  style: TextStyle(
                      fontSize: 30,
                      fontWeight: FontWeight.bold,
                      fontFamily: "FjallaOne"),
                ),
                leading: Container(),
                backgroundColor: Color(0xFFF0D5EAF),
              ),
              body: Container(
                child: Container(),
              ),
              drawer: Drawer(
                child: ListView(
                  children: [
                    Text(
                      "Hello world",
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
              ),
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-13
      • 2019-12-19
      • 1970-01-01
      • 2021-02-17
      • 2018-08-08
      • 2020-06-11
      • 2019-12-05
      相关资源
      最近更新 更多