gpt4 book ai didi

constructor - Dart Function.appy() 不适用于 Color.fromARGB(a, r, g, b);

转载 作者:IT王子 更新时间:2023-10-29 07:21:37 24 4
gpt4 key购买 nike

尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com