I'm having troubles using Navigator.popUntil to go back to the screen I need to go back to.
The app is part of a Web page and Screen/Navigation structure is :
HomePage pushes MainScreen(first app screen) that uses a Navigation bar to navigate through app's screens, one of which is PromotionsScreen.
Then PromotionScreen pushes to ChooseProductScreen with :
Navigator.push(
context,
MaterialPageRoute(
settings: RouteSettings(
name: 'PromotionsScreen'
),
builder: (_) =>
BlocProvider.value(
value: BlocProvider.of<
PromotionBloc>(
context),
child: ChooseProductScreen(
user: widget.user,
cityDb: widget.cityDb,
regionDb: widget.regionDb,
countryDb: widget.countryDb,
),
),
),
);
Then ChooseProductScreen pushes to NewEditPromotionScreen with :
Navigator.push(
// Navigator.pushReplacement( // Bloc event isn't sent from NewEditPromotionScreen
context,
MaterialPageRoute(
settings: RouteSettings(
name: 'ChooseProductScreen'
),
builder: (_) =>
BlocProvider.value(
value: BlocProvider
.of<
PromotionBloc>(
context),
child:
NewEditPromotionScreen(
type: 'New',
user: widget
.user,
cityDb:
widget.cityDb,
regionDb: widget
.regionDb,
countryDb: widget
.countryDb),
),
),
);
Now from NewEditPromotionScreen I want to go back to PromotionsScreen:
// pop CircularProgressIndicator Dialog
Navigator.of(context, rootNavigator: true).pop(context);
// pop the screen
// Navigator.popUntil(context, (route) => route.isFirst); // pops to HomePage
// Navigator.popUntil(context, (route) => route.settings.name == 'PromotionsScreen'); // pops to white screen
// Navigator.popUntil(context, ModalRoute.withName('PromotionsScreen')); // pops only to ChooseProductScreen
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (BuildContext context) => PromotionsScreen()), // Screen is not in NavigationBar
(route) => false);
I tried:
Navigator.popUntil(context, (route) => route.isFirst); but this will pop to the web page HomeScreen.
I tried giving a 'PromotionsScreen ' name in RouteSettings in PromotionsScreen when pushing to ChooseProductScreen, and then using Navigator.popUntil(context, ModalRoute.withName('PromotionsScreen')); but pops only until ChooseProductScreen.
Is this because 'PromotionsScreen' is the name of the route that pushes
to ChooseProductScreen so popUntil is actually working as expected?
If this is the case how can pop to PromotionsScreen instead as the route to it is managed by the NavigationBar?
I also tried :
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (BuildContext context) => PromotionsScreen()),
(route) => false);
but this would present the screen not in the navigation bar..
Can you spot what I'm doing worn using either way?
Many thanks for the help.