Reputation: 1805
I have a future and I want first optional parameter of that future to be an empty list. But dartanalyzer myFile.dart
returns this error:
[error] Default values of an optional parameter must be constant
(/home/user/projects/project/lib/myFolder/myFile.dart, line 7, col 48)
My code:
Future<dynamic> myFuture([List<Node> content = []]) async {
/*...*/
}
How can I get rid of this error?
Upvotes: 19
Views: 10726
Reputation: 76223
You need to use a constant as default parameter. To define a constant list you need to use the prepending const
keyword:
Future<dynamic> myFuture([List<Node> content = const []]) async {
/*...*/
}
Upvotes: 41