Dart optional parameter defaults?

I know that you can do this for things like Strings, ints, but I am wondering if you can set default values ​​for more complex data types like Maps. I tried with a new keyword and several other ways, but they all throw errors.

+4
source share
2 answers

The default parameters must be constants. You must define your default values ​​using the keyword const.

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

The default values ​​must be constants.

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

Source: https://habr.com/ru/post/1621306/


All Articles