簡體   English   中英

如何在 flutter 的 appBar 中停用或覆蓋箭頭返回按鈕?

[英]How to deactivate or override the arrow back button in the appBar in flutter?

有沒有辦法在特定頁面上停用箭頭后退按鈕? 我建立了一個啟動畫面,每當啟動畫面導航到主頁時,在主頁應用程序欄中,返回的箭頭會顯示,如何停用它或清除返回上一頁的箭頭(歡迎屏幕)。

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!")
    ),
  ),
),
);
}

在此處輸入圖像描述

將您的小部件包裝在WillPopScope中,並在onWillPop屬性中返回 false Future

    @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:如何在 flutter 中禁用手機后按

flutter 刪除應用欄上的后退按鈕

您可能會發現您的答案已在此問題中得到解答

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM