flutter-styleguide icon indicating copy to clipboard operation
flutter-styleguide copied to clipboard

Unused parameters in a method should be replaced with an underscore

Open rapPayne opened this issue 6 years ago • 1 comments

When providing a closure that accepts parameters for which you don't need to provide a value, it is recommended that you use the underscore/underbar character (_). For example, when creating routes in MaterialApp, you specify a context. Don't do this:

routes: {
  '/', (context) => SomeWidget(),
  '/route2': (context) => Widget2(),
}

Do:

routes: {
  '/', (_) => SomeWidget(),
  '/route2': (_) => Widget2(),
}

rapPayne avatar Oct 22 '19 16:10 rapPayne

I dont like hiding the context object in particular. Several times, I refactored the body of the method and used the parent's context instead of the builder context because of its _ name.

aloisdeniel avatar Jan 23 '20 02:01 aloisdeniel