Solvedflutter Bad state: Future already completed
✔️Accepted Answer
I had the same issue... The problem was the same that @soaresgabriel said, but I was not navigating directly from routes. I did navigate with the code below and I wasn't setting the name of it, like in the @soaresgabriel case.
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MyFuckingPage(),
),
);
Then I solved with:
Navigator.of(context).push(
MaterialPageRoute(
settings: RouteSettings(name: MyFuckingPage.routeName), <----------
builder: (context) => MyFuckingPage(),
),
);
and then the popUntil worked:
Navigator.of(context).popUntil(
ModalRoute.withName(MyFuckingPage.routeName));
@zoechi To me the error was also not clear... I just realized that the name was missing because I found this issu on flutter github.
Other Answers:
Same error with
Navigator.popUntil(context, ModalRoute.withName('/'));
It works in my case ! So this is how I solve.
I using popUntil
to back from pageC to pageA
PageC
Navigator.of(context).popUntil(ModalRoute.withName(PageA.ROUTE));
router.dart
case PageA.ROUTE:
return MaterialPageRoute(
settings: RouteSettings(name: PageA.ROUTE), // <--- Important line
builder: (_) => ProxyProvider<ABCRepository,ABCBloc>(
builder: (context, abcRepository, abcBloc) =>
ABCBloc(repository: repository),
dispose: (context, abcBloc) => abcBloc.dispose(),
child: PageA(),
),
);
I had a problem where I had 2 Navigators. the root navigator is used. https://stackoverflow.com/a/50683571/5115254
Navigator.of(context, rootNavigator: true).pop(result)
Steps to Reproduce
I'm calling:
and getting this error:
Logs
Flutter Doctor