您可以通过将空白
newContainer()作为
leading参数传递给来删除“后退”按钮
AppBar。
但是,如果您发现自己正在这样做,则可能不希望用户按下设备的“后退”按钮返回到先前的路线。而不是致电
pushNamed,请尝试致电
Navigator.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(), }, ); }}


