Kvu
Kvu

Reputation: 309

Two Types of Routes in Flutter

Navigator.of(context).pushNamedAndRemoveUntil('/something', (_) => false);

Navigator.of(context).pushNamedAndRemoveUntil('/something', (route) => false);

Hi what is the difference of this two? What's happening with routes and with underscore (_)???

Upvotes: 0

Views: 102

Answers (3)

Vettiyanakan
Vettiyanakan

Reputation: 8500

The _ operator is using when we are not accessing the object.

route is of type Route<dynamic> you can access the properties of Route class.

Upvotes: 1

Ivo
Ivo

Reputation: 23277

You can name the parameter however you like. All these are the same:

Navigator.of(context).pushNamedAndRemoveUntil('/something', (route) => false);
Navigator.of(context).pushNamedAndRemoveUntil('/something', (foo) => false);
Navigator.of(context).pushNamedAndRemoveUntil('/something', (bar) => false);
Navigator.of(context).pushNamedAndRemoveUntil('/something', (test) => false);
Navigator.of(context).pushNamedAndRemoveUntil('/something', (whatever) => false);

_ is used when you are not interested in the parameter. That you as developer won't be doing anything with the parameter.

Upvotes: 0

Robert Sandberg
Robert Sandberg

Reputation: 8637

There is no difference whatsoever when it comes to routing.

The only thing the underscore (_) indicates is that you, as a programmer, is not interested in using the builder argument (route) in this case.

Upvotes: 0

Related Questions