Skip to content

Convert nullable state fields to late or late final, if the fields are initialized in initState. #58675

@polina-c

Description

@polina-c

For example, for the code

class MyClassState extends State<MyClass> {
  MyClassState();

  String? _name;

  @override
  void initState() {
    super.initState();

    _name = detectName(); 
  }
...

The lint would suggest:

class MyClassState extends State<MyClass> {
  MyClassState();

  late final String _name;
  ...

(we should not do it for fields that are assigned to null in dispose)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions