Skip to content

Suggest final keyword for new Widget classes by default #176005

@loveoverflowcom

Description

@loveoverflowcom

Use case

Developers create new widgets frequently. Many of these widgets are not designed for inheritance.

By suggesting final, we prevent accidental subclassing, making the widget safer and signaling the intended use clearly.

Improves code readability and maintainability by indicating immutability at the class level.

Could potentially optimize performance, as Dart may optimize final classes better in certain scenarios.

Proposal

Currently, when creating a new Widget class in Flutter, IDEs and templates do not suggest using the final keyword for the class.

Most Widgets are not intended to be subclassed, and marking them as final improves code safety and can have minor performance benefits.

The proposal is to add a suggestion or template update in Flutter tools and IDEs so that when developers create a new Widget, the final keyword is recommended or auto-inserted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: proposalA detailed proposal for a change to Flutterp: flutter_lintsflutter/packages flutter_lintspackageflutter/packages repository. See also p: labels.team-devexpOwned by the Developer Experience teamtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions