devsin
devsin

Reputation: 155

Flutter, send parameter previous screen

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?

Upvotes: 1

Views: 2434

Answers (1)

Kirollos Morkos
Kirollos Morkos

Reputation: 2711

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

Upvotes: 3

Related Questions