Flutter-导航到新屏幕,然后清除以前的所有屏幕 [英] Flutter - Navigate to a new screen, and clear all the previous screens

查看:600
本文介绍了Flutter-导航到新屏幕,然后清除以前的所有屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最多使用6个屏幕上的Navigator.push进入付款页面.付款后,我想推送到付款成功"页面,然后删除所有以前的屏幕,即使用后退"按钮将返回到第一个屏幕.

I used Navigator.push up to 6 screens to get to the payment page. After Payment, I want to push to the "Payment Successful" page then remove all the previous screens i.e using the back button will return to the very first screen.

注意:我已经尝试过pushReplacementNamed,但是它不起作用.

NOTE: I have tried pushReplacementNamed and it doesn't work.

推荐答案

我知道了.这是Navigator.pushAndRemoveUntil函数.我必须将PaymentSuccessful小部件传递为newRoute,将"/Home"路由传递为谓词

I figured it out. It was the Navigator.pushAndRemoveUntil function. Where i had to pass the PaymentSuccessful widget as the newRoute, and the "/Home" route as the predicate

  _navPaymentSuccessful(){
    Navigator.pushAndRemoveUntil(
      context, 
      MaterialPageRoute(
        builder: (context) => PaymentSuccessful()
      ), 
     ModalRoute.withName("/Home")
    );
  }

这篇关于Flutter-导航到新屏幕,然后清除以前的所有屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆