簡體   English   中英

Flutter。 如何導航到新頁面而不保存到堆棧中

[英]Flutter. How to navigate to new page without save into the stack

如何導航到新頁面而不保存到堆棧中。 例如我有兩個頁面:A 和 B。從頁面 A 你可以打開 B; 從B你可以打開A。我希望B的每次打開都不會被保存到“歷史”中。 因此,從 A 向后壓不能回到 B。

在 android 中,它可以在意圖標志的幫助下實現。 例如:

Intent i = new Intent(...); // my Activity B
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // Adds the FLAG_ACTIVITY_NO_HISTORY flag, which keeps the new Activity from being added to the history stack.
startActivity(i);

是否可以在 flutter 上實現此行為,請幫助我。

您可以使用pushReplacement來實現這一點。 從您的頁面 B 中,每當您導航到頁面 A 時,請使用以下代碼:

Navigator.pushReplacement(
   context,
   MaterialPageRoute(
      builder: (BuildContext context) => PageA()
  )
);

閱讀Navigator中所有可用的導航選項。

暫無
暫無

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

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