0
votes

Is there a way to deactivate the arrow back button when on a specific page? I built a splash screen and whenever the splash screen navigates to the HomePage, in the HomePage appBar the arrow for going back shows, How can I deactivate it or clear the arrow from going back to the previous page(welcome screen).

Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {return Future.value();
}, // async => true,
child: Scaffold(
  appBar: AppBar(
    title: Text("Application!"),
    elevation: 20,
    centerTitle: true,
    actions: <Widget>[
      IconButton(
        icon: Icon(Icons.exit_to_app),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
      PopupMenuButton(
        icon: Icon(Icons.more_vert),
        itemBuilder: (context) => [
          PopupMenuItem(
            child: Text("Home"),
          ),
          PopupMenuItem(
            child: Text("Hire"),
          ),
          PopupMenuItem(
            child: Text("Settings"),
          ),
          PopupMenuItem(
            child: Text("About"),
          ),
        ],
      ),
    ],
  ),
  body: Center(
    child: Container(
      child: Text("Chech out my new Mobile Applications!")
    ),
  ),
),
);
}

enter image description here

2

2 Answers

1
votes

Wrap your widget inside WillPopScope and return a false Future in the onWillPop property.

    @override
    Widget build(BuildContext context) {
      return WillPopScope(
        onWillPop: () => Future.value(false),
        child: Scaffold(
          appBar: AppBar(
            title: const Text("Home Page"),
          ),
          body: Center(
            child: const Text("Home Page"),
          ),
        ),
      );
    }

REF: how to disable phone back press in flutter

0
votes

flutter remove back button on appbar

you might find your answer is already answered in this questions