CHOI YOOBIN
CHOI YOOBIN

Reputation: 176

How do I delete all of the pages stacked through push in bottom navigation?

I use the bottom navigation bar. Various pages remain stacks through push on A_Page, one of the bottom navigation items.

If you press the button on the top page, I want to clear all stacked pages, leaving only A_Page, the first page of the bottom navigation item. I think using Navigator.pop several times is a bad code.

How do I clear a pushed page except the first bottom navigation item page?

Upvotes: 0

Views: 560

Answers (2)

Lee3
Lee3

Reputation: 3077

Navigator.popUntil(context, (route) => route.isFirst);

Upvotes: 1

Ganeshprasad Shenoy
Ganeshprasad Shenoy

Reputation: 76

You can use named routes

Navigator.of(context).pushNamedAndRemoveUntil(
   '/first_screen',
   (Route<dynamic> route) => false,
);

Upvotes: 0

Related Questions