سؤال

I am wondering is there is a way to use named optional parameters in subclass.

ex:

class A {
  num min;
  num max;
  A({min: 1, max: 10});
}

class B extends A {
  num step;
  B({min: 2, max, step: 1}) : super(min, max);
}

This does not work, so I am wondering what would.

The main idea is that I subclass a class and override the methods and maybe I have an additional optional parameter in the subclass, but I want to reuse the super-class parameters. How do I do that in Dart?

هل كانت مفيدة؟

المحلول

If it is a named optional parameter you must provide the name:

class A {
  num min;
  num max;
  A({min: 1, max: 10});
}

class B extends A {
  num step;
  B({min: 2, max, step: 1}) : super(min: min, max: max);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top