Flutter,如何删除导航中的后退按钮?
登录后我的Homepage.dart里有这段代码,不知能否去掉导航栏中的后退按钮,请看下图
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My Flutter App'),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: 0, // this will be set when a new tab is tapped
items: [
BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text('Home'),
),
BottomNavigationBarItem(
icon: new Icon(Icons.mail),
title: new Text('Messages'),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
title: Text('Profile')
)
],
),
);
}
}
我就是这样称呼主页的
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => HomePage()));
}
回答
而不是调用PushtryNavigator.of(context).pushNamedAndRemoveUntil(newRouteName, (route) => false)这将使用新路由删除先前的路由。
和一个简单的方法来删除后退按钮
appBar: AppBar( title: Text("App Bar without Back Button"), automaticallyImplyLeading: false, ),