Can I assign a reference to a constructor in Dart?

2065 views dart
9

My use case is in constructing a WidgetApp in flutter:

new WidgetsApp(
  pageRouteBuilder: <Contructor for MaterialPageRoute here>,
  ...
);

instead of referencing the constructor I'm just wrapping it in a function

PageRoute pageRouteBuilder(RouteSettings settings, WidgetBuilder builder) {
    return MaterialPageRoute(settings: settings, builder: builder);
}

and then referencing that function

new WidgetsApp(
  pageRouteBuilder: pageRoutbuilder,
  ...
);

answered question

1 Answer

1

It used to be possible at some point in the history of Dart (like spread operator). It is currently not possible though, but the feature may come back at some point.

In the meantime, you can use refactoring options for them to generate some of the boilerplate.

posted this

Have an answer?

JD

Please login first before posting an answer.