ios developer
ios developer

Reputation: 3473

Hide back button in flutter

I am using statefull and stateless widget for some of screens in flutter.

I want to hide back button is some screen and wanted to display back button is some screen how can i do it. I had not written any code for back button it just appear by default.

I am using below code to push to another screen with parameter

Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => Nextscreen('parameter1','Parameter2'),
          ));

or below code when there is no parameter : Navigator.of(context).pushNamed(NEXT_SCREEN);

Upvotes: 4

Views: 3950

Answers (2)

Elias Teeny
Elias Teeny

Reputation: 614

If you want to hide the back button in the AppBar of your Scaffold page pass AppBar the property automaticallyImplyLeading with a value of false:

  appBar: AppBar(
    automaticallyImplyLeading: false,
    ...
  )

Upvotes: 12

Abion47
Abion47

Reputation: 24606

In the screen where you make the Scaffold, you can pass something to the leading property of the AppBar and it will override the default back button widget appearing. So if you wanted nothing there, you could just pass an empty Container when your parameter is present and null otherwise:

Scaffold(
  appBar: AppBar(
    leading: widget.parameter1 ?? Container() : null,
    ...
  ),
  ...
),

Upvotes: 1

Related Questions