Tanzeem Iqbal
Tanzeem Iqbal

Reputation: 171

Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3803 pos 12: '_history.isNotEmpty': is not true

i used persistent_bottom_nav_bar library in my app. When i use Navigator to display a new screen then error show.

InkWell(
    onTap: () {
      Navigator.of(context).popUntil(ModalRoute.withName("previousjob"));
      Navigator.of(context).pushAndRemoveUntil(
        CupertinoPageRoute(
          builder: (BuildContext context) {
            return SettingMenu();
          },
        ),
        (_) => true,
      );
    },

Upvotes: 13

Views: 19821

Answers (5)

Hamid Waezi
Hamid Waezi

Reputation: 895

This happen when your route stack is empty. just befor call pop(), check it that capPop() or maybePop() return true.

Upvotes: 1

J. Diaz
J. Diaz

Reputation: 421

Resolved! In my case, I was using this:

Navigator.of(context).pushReplacement(MaterialPageRoute())

I changed to this:

Navigator.push(context, MaterialPageRoute())

Upvotes: 1

Achintha Isuru
Achintha Isuru

Reputation: 3347

In my case, it was because I tried to call pop after I have called pushAndRemoveUntil. After I remove the above-mentioned pop it worked fine.

Upvotes: 3

Axes Grinds
Axes Grinds

Reputation: 993

I solved the issue in my code. My issue is that I was called navigator pop twice in a particular situation which caused the error.

Upvotes: 20

Ridham Desai
Ridham Desai

Reputation: 85

This is my 1st answer so might not be very clear. But from what I understood while having this same problem is, you need to use push first before you can actually use pop.

You are using pop first so there is nothing into your history.

Try:

    InkWell(
        onTap: () {
          Navigator.of(context).pushNameed(ModalRoute.withName("previousjob"));
          Navigator.of(context).pushAndRemoveUntil(
            CupertinoPageRoute(
              builder: (BuildContext context) {
                return SettingMenu();
              },
            ),
            (_) => true,
          );
        },

Upvotes: 6

Related Questions