尝试使用 Function.apply() 传递位置参数列表。但是为什么构造函数方法不适用于 Color 类?
var x = Function.apply(Color.fromARGB, [255, 66, 165, 245]);
Error Message: The getter 'fromARGB' isn't defined for the class 'Color'.
这是构造函数。
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;
最佳答案
命名构造函数不是 Dart 中的 Function
。
当前编写示例的方法是:
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是跟踪请求支持“撕掉”构造函数以将其视为 Function
的规范问题。
关于constructor - Dart Function.appy() 不适用于 Color.fromARGB(a, r, g, b);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55349335/