Skip to content

Handle ?? operator precedence #1

@vlastachu

Description

@vlastachu

It is common way to write widget which can optionally take controller as its own property.

You should handle null case for such controller in initState or lazy variable declaration:

  late final _controller =
        widget.controller ?? TextEditingController(text: widget.initialValue);

lint suggest you next rewriting:

  late final _controller =
        widget.controller ?? TextEditingController(text: widget.initialValue).closeWith(this);

which you can read as

  late final _controller =
        widget.controller ?? (TextEditingController(text: widget.initialValue).closeWith(this));

but it is actually

  late final _controller =
        (widget.controller ?? TextEditingController(text: widget.initialValue)).closeWith(this);

So in case when widget's property controller is not null it will possibly closed sooner than it should.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions