Search code examples
flutterback-button

Disable hardware/device back button but Appbar back button should be enabled


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


Solution

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

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