Experimenting with Function.apply() to pass a list of positional parameters. But why doesn't a constructor method work for class Color?
var x = Function.apply(Color.fromARGB, [255, 66, 165, 245]);
Error Message: The getter 'fromARGB' isn't defined for the class 'Color'.
Here is the constructor.
const Color.fromARGB(int a, int r, int g, int b) :
value = (((a & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF;
A named constructor is not a Function
in Dart.
The current way to write your sample is:
var x = Function.apply(
(int a, int r, int g, int b) => Color.fromARGB(a, r, g, b),
[255, 66, 165, 245]);
https://github.com/dart-lang/language/issues/216 is the canonical issue to track requesting support for "tearing off" a constructor to treat it as a Function
.
User contributions licensed under CC BY-SA 3.0