Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);

like image 647
ios developer Avatar asked Oct 23 '25 14:10

ios developer


2 Answers

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,
    ...
  )
like image 99
Elias Teeny Avatar answered Oct 26 '25 05:10

Elias Teeny


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,
    ...
  ),
  ...
),
like image 29
Abion47 Avatar answered Oct 26 '25 06:10

Abion47



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!