这是indexloc提供的服务,不要输入任何密码
Skip to content

Ability to provide constructor that forwards all arguments #493

@Hixie

Description

@Hixie

Consider someone creating a Flutter package that extends a bunch of widgets with an extra argument, for example adding an isEnabled argument to every button, which changes how the onPressed argument gets forwarded.

Currently, if they do this, every time the superclass constructor is changed, they have to republish their package with an update. This leads to the likelihood that the package will eventually be abandoned and won't be updated (since that is work). It also means the package will only work with some versions (those that match the API the package expected).

Imagine if instead they could provide a constructor that is defined to have all the arguments of the superclass, with just a few "edits", as in:

  class MySuperButton extends Button {
    MySuperButton(...super, { bool isEnabled })
     : super(
          onPressed: isEnabled ? onPressed : null,
          ...super,
       );
  }

...where ...super stands for "fill in everything from the superclass that isn't overridden here".

See also dart-lang/sdk#22274 which is similar but doesn't involve overriding. This proposal would make that one irrelevant (it just becomes MySuperButton(...super) or some such).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions