How can I hide the AppBar back button based on the platform?
Solution 1
Set that value based on the platform. You can get the platform with https://pub.dev/packages/platform, like so:
AppBar(automaticallyImplyLeading: !Platform.isAndroid, ...)
which will make it false on Android, true everywhere else. You might need to add other platforms if you find it necessary.
Solution 2
You can simply hide it conditionally:
import 'dart:io';
AppBar(
automaticallyImplyLeading: !Platform.isAndroid,
...,
)
This will only hide the back button on Android.
Learn more about Platform.isAndroid
.
Lane Faison
Updated on December 07, 2022Comments
-
Lane Faison over 1 year
I am hoping to hide all
AppBar
back buttons throughout my app for Android users, so that they must use the device's back button instead. But for iOS users, I would like for theAppBar
's back button to be present since that is the standard way to navigate.What is the best way to achieve this and is there a way to do it globally using
AppBarTheme
?I am aware of
AppBar(automaticallyImplyLeading: false, ...)
but that hides the back button on both iOS and Android devices. -
Randal Schwartz over 3 yearsYou missed a "not".
-
creativecreatorormaybenot over 3 years@RandalSchwartz Thanks :)