[英]Close the application on back press
我正在使用appbar
進行開發,我想在用戶點擊應用欄上的后退圖標時將應用程序發送到后台或關閉它
我已經使用這個答案作為參考,但除了exit(0)
之外沒有任何作用,iOS 中不推薦這樣做。
我嘗試遵循其他答案的建議,但沒有一個適用於 iOS。
Navigator.of(context).pop();
Navigator.of(context).maybePop();
Navigator.of(context, rootNavigator: true).pop(context);
Navigator.pushReplacementNamed(context, '/route');
SystemNavigator.pop();
Navigator.pop(context,true);
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
對於 android 以下工作正常。
SystemNavigator.pop();
我應該使用什么來關閉蘋果指南中的應用程序。
編輯
SystemNavigator.pop();
在 iOS 中出現黑屏。
嘗試這個
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
),
title: Text("Sample"),
centerTitle: true,
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.