Ash
Ash

Reputation: 896

Dart optional parameter default values?

I know you can do this for things like Strings, ints, but I'm wondering if you can set default values for more complex data types such as Maps. I've tried with the new keyword and a few other ways, but they all throw errors.

Upvotes: 7

Views: 1982

Answers (2)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657366

Default values need to be constants.

someFunc({someParam = const {'a': 'b'} }) => someParam;

Upvotes: 5

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76213

Default parameters have to be constants. You have to define your default values with the const keyword.

m([p1 = const['a', 'b']]) => null;

Upvotes: 7

Related Questions