Fix hot reload when using the Watch widget #398
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #390
result.recompute();
in the addPostFrameCallback might get called with an invalid widget context on hot reload. I don't think this block is really needed, because didUpdateWidget is already taking into consideration the builder changing to properly update the "cached" widget signal.I've tried and it seems to be working ok. Alternatively, if we want to keep the callback, we can add
if (!mounted) return
at the very beginning. This is the first thing I changed, but then I noticed that on hot reloads, the computed widget signal was being recomputed twice (one the callback and the other the didUpdateWidget), that's why I opted to kee the didUpdateWidget recompute only.Also, I believe the didUpdateWidget needs to be a separate if statement, not if-else. Otherwise, we don't recompute if the dependencies list changes and the builder also changes.