我想知道,如果有人知道一种方法,以删除显示在appBar在颤振应用程序,当你使用Navigator。pushNamed转到另一个页面。我不希望它出现在这个结果页面上的原因是它来自导航,我希望用户使用注销按钮,这样会话就可以重新开始。


当前回答

我认为解决办法如下

你实际上可以:

Don't want to display that ugly back button ( :] ), and thus go for : AppBar(...,automaticallyImplyLeading: false,...); Don't want the user to go back - replacing current view - and thus go for: Navigator.pushReplacementNamed(## your routename here ##); Don't want the user to go back - replacing a certain view back in the stack - and thus use: Navigator.pushNamedAndRemoveUntil(## your routename here ##, f(Route<dynamic>)→bool); where f is a function returning truewhen meeting the last view you want to keep in the stack (right before the new one); Don't want the user to go back - EVER - emptying completely the navigator stack with: Navigator.pushNamedAndRemoveUntil(context, ## your routename here ##, (_) => false);

其他回答

我认为解决办法如下

你实际上可以:

Don't want to display that ugly back button ( :] ), and thus go for : AppBar(...,automaticallyImplyLeading: false,...); Don't want the user to go back - replacing current view - and thus go for: Navigator.pushReplacementNamed(## your routename here ##); Don't want the user to go back - replacing a certain view back in the stack - and thus use: Navigator.pushNamedAndRemoveUntil(## your routename here ##, f(Route<dynamic>)→bool); where f is a function returning truewhen meeting the last view you want to keep in the stack (right before the new one); Don't want the user to go back - EVER - emptying completely the navigator stack with: Navigator.pushNamedAndRemoveUntil(context, ## your routename here ##, (_) => false);

您可以通过传递一个空的新Container()作为AppBar的前导参数来删除返回按钮。

如果你发现自己这样做了,你可能不希望用户能够按下设备的后退按钮回到之前的路线。与其调用pushNamed,不如尝试调用Navigator。pushReplacementNamed将导致先前的路由消失。

函数pushReplacementNamed将删除后堆栈中的先前路由,并用新路由替换它。

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

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(),
      },
    );
  }
}
  appBar: new AppBar(title: new Text("SmartDocs SPAY"),backgroundColor: Colors.blueAccent, automaticallyImplyLeading:false,
        leading: new Container(),
      ),

工作正常

如果导航到另一个页面。可以使用Navigator.pushReplacement()。如果你从登录导航到主屏幕,它可以被使用。或者你可以用。 AppBar (automaticallyImplyLeading: false)

只是让它透明,没有行动,而现在

AppBar(
            leading: IconButton(
              icon: Icon(
                Icons.arrow_back,
                color: Colors.white.withOpacity(0),
              ),
              onPressed: () {},
            ),