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

标签 constructor dart flutter

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

相关文章:

c++ - 在另一个类中使用对象的构造函数

android - flutter 错误 : RangeError (index): Invalid value: Not in range 0. .2,包括:3

Java 构造函数,在哪里放置一次繁重的初始化?

java - 如何在资源父类的构造函数中访问HttpServletRequest?

flutter - 带有 SliverAppBar 的 NestedScrollView 导致意外的 body 填充

layout - Flutter 布局容器边距

flutter - 如何在 Flutter 中重置 Hive 数据库

Flutter 国际化,国际代码生成不起作用

dart - Flutter Navigator.pop(context) 返回黑屏

pointers - 结构构造函数的奇怪行为