Home > Mobile >  Two Types of Routes in Flutter
Two Types of Routes in Flutter

Time:08-24

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 (_)???

CodePudding user response:

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.

CodePudding user response:

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.

CodePudding user response:

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.

  • Related