0

Let me explain, I have two listeners, one in ScreenA, and another in ScreenB, however both have the same state that does different actions, example:

ScreenA

listener : (BuildContext context, StateA state) {

if (state is SuccessB) {
  ... show snackbar
}

if (state is GoToScreenBState) {

  Navigator.of(context).pushReplacementNamed(PageNames.screenB);

}

ScreenB

listener : (BuildContext context, StateA state) {

if (state is SuccessB) {
  ... another code

  BlocProvider.of<ABloc>(context).add(GoToScreenAEvent()); // emit the GoToScreenAState
}

if (state is GoToScreenAState) { // this is the state above

  Navigator.of(context).pushReplacementNamed(
     PageNames.screenA,
     (Route<dynamic> route) => false,
  ); // return to A

}

Now, when I go back to ScreenA, I emit again SuccessB so that the listener of that screen is executed, but also the one of ScreenB is executed, I don't understand why if I already navigue and replace...

Any idea ?

Daniel Roldán
  • 1,328
  • 3
  • 20
  • Why don't you do a pop instead of a pushReplacement? I think something is not working on the navigation and the ScreenB is remaining inside the navigation stack. Can you check the Flutter Inspector? – Caffo17 Apr 07 '22 at 10:57
  • @Caffo17 where can i see the ino navigation ? – Daniel Roldán Apr 07 '22 at 13:33
  • In the Flutter Inspector you can see it. If you are using Android Studio, it's a tab on the right. If you are using VSCode you need to launch it. Check [here](https://stackoverflow.com/questions/51341918/flutter-inspector-in-visual-studio-code) – Caffo17 Apr 08 '22 at 17:54

0 Answers0