颤动删除应用栏上的后退按钮 [英] flutter remove back button on appbar

查看:27
本文介绍了颤动删除应用栏上的后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,当您使用 Navigator.pushNamed 时,是否有人知道如何删除显示在颤动应用程序中的 appBar 上的后退按钮到另一页.我不想在这个结果页面上显示它的原因是它来自导航,我希望用户改用 logout 按钮,以便会话重新开始.

I am wondering, if anyone knows of a way to remove the back button that shows up on the appBar in a flutter app when you use Navigator.pushNamed to go to another page. The reason I do not want it on this resulting page is that it is coming from the navigation and I want users to use the logout button instead, so that the session starts over.

推荐答案

您可以通过传递一个空的 new Container() 作为 leading 参数给你的 AppBar.

You can remove the back button by passing an empty new Container() as the leading argument to your AppBar.

如果您发现自己这样做,您可能不希望用户能够按下设备的后退按钮返回到较早的路线.不要调用 pushNamed,而是尝试调用 Navigator.pushReplacementNamed 使之前的路由消失.

If you find yourself doing this, you probably don't want the user to be able to press the device's back button to get back to the earlier route. Instead of calling pushNamed, try calling Navigator.pushReplacementNamed to cause the earlier route to disappear.

函数 pushReplacementNamed 将删除 backstack 中的先前路由并将其替换为新路由.

The function pushReplacementNamed will remove the previous route in the backstack and replace it with the new route.

后者的完整代码示例如下.

Full code sample for the latter is below.

import 'package:flutter/material.dart';

class LogoutPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Logout Page"),
      ),
      body: new Center(
        child: new Text('You have been logged out'),
      ),
    );
  }

}
class MyHomePage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Remove Back Button"),
      ),
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.fullscreen_exit),
        onPressed: () {
          Navigator.pushReplacementNamed(context, "/logout");
        },
      ),
    );
  }
}

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      home: new MyHomePage(),
      routes: {
        "/logout": (_) => new LogoutPage(),
      },
    );
  }
}

这篇关于颤动删除应用栏上的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆