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);
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,
...
)
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,
...
),
...
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With