0

I am a beginner in Dart. :-)

I wonder why I can't call the parent class constructor inside the child class constructor body.

class Parent {
  String? name;

  Parent(this.name);
  Parent.namedConstructor(this.name);
}

class Child extends Parent {
  // Child(String name) : super(name); // It's OK
  // Child(String name) : super.namedConstructor(name); // It's OK, too.

  Child(String name) {
    super(name); // Error
    super.namedConstructor(name); // Error
  }
}
plztrial4me
  • 181
  • 1
  • 7
  • See https://stackoverflow.com/a/63319094/. When the constructor body is entered, the object is expected to be initialized and `this` is now valid, and that requires that all base class constructors have already executed. – jamesdlin Mar 18 '22 at 11:05

0 Answers0