Home > Mobile >  Disable hardware/device back button but Appbar back button should be enabled
Disable hardware/device back button but Appbar back button should be enabled

Time:09-30

WillPopScope(
    onWillPop: () => Future.value(allowHardwareBack),  // allowHardwareBack flag to enable/disable
    child: Scaffold(body: Body())
)

What I am getting : The above code disables the back functionality from device back button and from the Appbar back button as well.

What I want to acheive : The AppBar back button (i.e back arrow leading icon) should be enabled regardless of device back button enabled or disabled

CodePudding user response:

Use your own custom back arrow with the help of leading property:

leading: IconButton(
  icon: Icon(Icons.arrow_back),
  onPressed: () => Navigator.of(context).pop(),
), 
  • Related