1

I have two screens A and B. I clicked a button from A and open B screen. When opened B screen I choose something and go back to A screen with:

      Navigator.pop(context, MaterialPageRoute(builder: (context) => A(data: data)));

but it doesn't work.

How can go back to the previous screen with data using pop or similar things?

devsin
  • 155
  • 3
  • 13

1 Answers1

3

the pop method takes an optional parameter that you can return to the previous screen. You would use it like so:

// In screen A:
final result = await Navigator.push(...); // Here you just push the route like normal

// In screen B:
Navigator.pop(context, data); // Where data is whatever you want to return to screen A

In the above example, result will contain whatever you returned from screen B

Kirollos Morkos
  • 2,503
  • 16
  • 22