超级方法有什么问题?

what is the proplem in super method?

我在这段代码中遇到了 dart 问题:

void main() {
    Mobile OPPO = Mobile(
        color: 'yellow',
        price: 5500,
    );

    OPPO.printColor();
    OPPO.printPrice();
}

class Devices {
    String? color;
    int? price;
}

class Mobile extends Devices {
    Mobile({
        String? color,
        int? price,
    }) : super(color=color, price=price);

    void printColor() {
        print(color);
    }

    void printPrice() {
        print(price);
    }
}

lib/Test%20oop.dart:19:13: Error: Too many positional arguments: 0 allowed, but 2 found.
Try removing the extra positional arguments. }) : super(color=color, price=price);
^

Class Devices 缺少构造函数,dart 表示默认 Devices() 所以它没有参数但你传递了 2。要解决此问题,请创建具有 2 个参数的 Devices 构造函数.

附加:超级使用:而不是=