ThitSarNL
ThitSarNL

Reputation: 720

What is different between named route and navigate screen in Flutter?

I found ways of passing arguments in 2 ways. Send data to a new screen https://flutter.dev/docs/cookbook/navigation/passing-data and Pass arguments to a named route https://flutter.dev/docs/cookbook/navigation/navigate-with-arguments. What is difference between them?

Upvotes: 3

Views: 1710

Answers (1)

Mikhail Ponkin
Mikhail Ponkin

Reputation: 2711

First example uses Navigator.push method where widget A passes arguments directly to new widget B constructor. Second example uses Navigator.pushNamed with route name with arguments passed as separate field. So new MaterialPageRoute with widget B is built somewhere else, where you handle routes.

2nd approach is more flexible because it allows to untie widgets A and B, so widget A does not know what widget is instantiated after pushing named route.

But both approaches will work so it's up to you to decide which one to use.

Upvotes: 3

Related Questions