Incomplete or missing didUpdateWidget method #58333
Labels
area-devexp
Developer Experience related issues (DevTools, IDEs, Analysis Server, completions, refactoring, etc)
customer-flutter
devexp-linter
Issues with the analyzer's support for the linter package
linter-lint-request
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
Flutter developers are unable to hot reload as many changes to the parameters of StatefulWidgets as they should because
didUpdateWidget
is often not implement or not implement fully. Apps can also suddenly start failing in confusing ways due to changes at a distance that cuase Flutter to reuse State objects where it didn’t before exposing these bugs.Describe the rule you'd like to see implemented
The lint should trigger if a Flutter
State
object'sinitState
method stores values from fields of a widget butdidUpdateWidget
does not at minimum have a code path that reads those same fields. This will require flow analysis within the State class as it is common to have helper methods called from bothinitState
anddidUpdateWidget
that update theState
object to match the widget. We will need to carefully track how many false positives this lint triggers. If the flow analysis is robust there should be few very few positives but there may be some false negatives where the lint thinksdidUpdateWidget
methods are fine even though they have bugs as we cannot ensure the logic indidUpdateWidget
is correct only that it is not neglecting members from the widget. If it doesn't introduce significant false positives, we could warn about absolutely any member use ininitState
that is not also matched by member use indidUpdateWidget
.Examples
All of these examples are members of a State object
No lint error in this case. There is an initState but no didUpdateWidget method but that does not indicate a bug as initState does not read any data off the widget.
Ideally, provide motivating examples w/ rationale.
Additional context
We find in practice that users very frequently neglect to implement
didUpdateWidget
as issues tend to only show up on a hot reload or rare cases where the same Widget objectThe text was updated successfully, but these errors were encountered: