Why use onGenerateRoute() vs ModalRoute.of() in Flutter?

Posted by Jennifer | Updated on

Why use onGenerateRoute() vs ModalRoute.of() in Flutter?

ModalRoute.of is used to build the route after it has been pushed in the navigation history.

onGenerateRoute does the same, but before that route is pushed in the navigation history.

ModalRoute.of is enough for most use-cases. But onGenerateRoute is more flexible. It allows building the route conditionally based on what the argument is, or type checking that the argument is valid:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers