6

I have this code in my Homepage.dart after the login, I wonder if i can remove the backbutton in the navigation bar, please see the picture below

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')
          )
        ],
      ),
    );
  }
}

this is how i call the Homepage

onPressed: () {
    Navigator.push(context, MaterialPageRoute(builder: (_) => HomePage()));
} 

enter image description here

1 Answers1

25

Instead of calling Push try Navigator.of(context).pushNamedAndRemoveUntil(newRouteName, (route) => false) This will remove the previous route with new one.

And a simple way to remove the back button

appBar: AppBar( title: Text("App Bar without Back Button"), automaticallyImplyLeading: false, ),

Zohaib Tariq
  • 548
  • 8
  • 15