Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor of subclass is incredibly verbose #36978

Open
MilesAdamson opened this issue May 15, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@MilesAdamson
Copy link

commented May 15, 2019

Issue when invoking super of parent class. You have to write out every viable twice, once in the child constructor and then again inside super(). This is very verbose for classes with many variables. A constructor I just wrote at work was 32 lines.

But if I had syntax to say "you must pass every variable the super class needs" it would be only 1 line.

void main() {
     var child = Child(one: 1, two: 2, three: '3', childVar: 4);  
     print(child.childVar);
}

class Parent {
    final varOne;
    final varTwo;
    final varThree;
  Parent({this.varOne, this.varTwo, this.varThree});
}

class Child extends Parent {

  final childVar;

  // No way to implicitly require/pass everything for super
  Child(
      {int one,
      int two,
      String three,
      this.childVar})
        : super(
          varOne: one,
          varTwo: two,
          varThree: three);
}

I would like to be able to do something like this:

  // You must pass in every variable the super class requires
  Child({this.childVar}) : super(...);

@MilesAdamson MilesAdamson changed the title Constructor of extended class is incredibly verbose Constructor of subclass class is incredibly verbose May 15, 2019

@MilesAdamson MilesAdamson changed the title Constructor of subclass class is incredibly verbose Constructor of subclass is incredibly verbose May 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.