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

Handle ?? operator precedence #1

Open
vlastachu opened this issue Dec 20, 2023 · 0 comments
Open

Handle ?? operator precedence #1

vlastachu opened this issue Dec 20, 2023 · 0 comments
Labels

Comments

@vlastachu
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant