【问题标题】:Removing the default back arrow on certain pages删除某些页面上的默认后退箭头
【发布时间】:2023-03-27 12:23:01
【问题描述】:

据我了解,默认情况下导航到任何页面后都会出现一个后退箭头。有没有办法不在我选择的某个页面上包含后退箭头?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    在 AppBar 中将 automaticallyImplyLeading 设置为 false 或在 leading

    中分配 empty container

    使用自动ImplyLeading

    appBar: new AppBar(
       title: new Text("Your Text Here"), 
       automaticallyImplyLeading: false,
    ),
    

    使用空容器

    appBar: new AppBar(
       title: new Text("Your Text Here"), 
       leading: new Container(),
    ),
    

    【讨论】:

      【解决方案2】:

      要隐藏后退按钮,请将Appbar的automaticallyImplyLeading属性设置为false

      new Scaffold(
                  appBar: new AppBar(
                    automaticallyImplyLeading: false,
                  )
      )
      

      【讨论】:

        【解决方案3】:

        https://stackoverflow.com/a/44978595/3013538 的副本

        我认为解决方案如下

        你实际上是:

        • 不想显示那个丑陋的后退按钮 (:]),因此选择: AppBar(...,automaticallyImplyLeading: false,...);

        • 不希望用户返回 - 替换当前视图 - 因此选择: Navigator.pushReplacementNamed(## your routename here ##);

        • 不希望用户返回 - 将某个视图替换回堆栈中 - 因此使用: Navigator.pushNamedAndRemoveUntil(## your routename here ##, f(Route<dynamic>)→bool); 其中 f 是一个函数返回true当遇到你想保留在堆栈中的最后一个视图(就在新视图之前);

        • 不希望用户返回 - EVER - 完全清空导航器堆栈: Navigator.pushNamedAndRemoveUntil(## your routename here ##, (_) => false);

        干杯

        【讨论】:

          【解决方案4】:

          根据AppBar docs

          如果前导小部件被省略,... 否则,如果最近的 Navigator 有任何先前的路由,则插入 BackButton。

          所以你可以用这种方式隐藏它

          new Scaffold(
                    appBar: new AppBar(
                      title: new Text("Without back button"),
                      leading: new Container(),
                    ),
                  );
          

          【讨论】:

          • 非常感谢
          • 如果页面被用作应用程序的主页(没有Navigator.push),这似乎会导致显示后退按钮通常所在的空白区域的副作用。 automaticallyImplyLeading: false,正如 Fabio 在另一个答案中所建议的那样,似乎是一个优雅的解决方案。
          猜你喜欢
          • 1970-01-01
          • 2023-03-17
          • 1970-01-01
          • 1970-01-01
          • 2013-09-27
          • 2018-03-15
          • 1970-01-01
          • 1970-01-01
          • 2017-03-30
          相关资源
          最近更新 更多