I have 5 screens.
The 5th screen has a button go to the 1st screen.
I clicked the 1st screen and 2nd screen and 3rd screen and 4th screen and 5th screen again clicked the 1st screen and 2nd screen and 3rd screen and 4th screen and 5th screen. (1>2>3>4>5>1>2>3>4>5)
I clicked back button again and again.not stopping in 1st page. go to I visited every page. (5<4<3<2<1<5<4<3<2<1)
I used WillPopScope
When you are going from 5th screen to 1st screen, you should not push the 1st screen. Instead, you should use popUntil
to pop until you get back to 1st screen.
For this, you're going to have to add a named route to 1st screen, so that you can use something like ModalRoute.withName('/login')
as shown in the example here.
This question seems to be closely related: Flutter Navigation pop to index 1