-
Notifications
You must be signed in to change notification settings - Fork 2
Handle ?? operator precedence #1
Copy link
Copy link
Open
Labels
Description
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.
Reactions are currently unavailable