skip to Main Content
 bool isChecked = false;

  void isValidate() {
    if (_formKey.currentState != null) {
      if (_formKey.currentState!.validate()) {
        print("is valid");
        Navigator.of(context).pushAndRemoveUntil(
            MaterialPageRoute(
              builder: (context) => AnaSayfaView(),
            ),
            (route) => false);
      } else {
        print("is not valid");
      }
    }
  }

I have this code. The error message says:

A page-based route cannot be completed using imperative api, provide a new list without the corresponding Page to Navigator.pages instead.’package:flutter/src/widgets/navigator.dart’:navigator.dart:1Failed assertion: line 3040 pos 7: ‘!pageBased || isWaitingForExitingDecision’

I have tried to navigate another page and not turning back to same page again.

2

Answers


  1. How the PushAndRemoveUntil function works is that it keeps calling the method until when the result gets a true result. Since you are always sending false as the result it will not work.

    Try the following – it will remove remove all page up to the first one and then push that page.

      bool isChecked = false;
      void isValidate() {
        if (_formKey.currentState != null) {
          if (_formKey.currentState!.validate()) {
            print("is valid");
            Navigator.of(context).pushAndRemoveUntil(
                MaterialPageRoute(
                  builder: (context) => AnaSayfaView(),
                ),
                (route) => route.isFirst);
          } else {
            print("is not valid");
          }
        }
      }
    
    Login or Signup to reply.
  2. Try this

     WidgetsBinding.instance!.addPostFrameCallback((_) {
        Navigator.of(context).pushAndRemoveUntil(
                MaterialPageRoute(
                  builder: (context) => AnaSayfaView(),
                ),
                (route) => false);
        });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search