fix: react to ConfettiWidget colors updates - #105
Open
erperejildo wants to merge 1 commit into
Open
Conversation
Handle didUpdateWidget in _ConfettiWidgetState so changes to the `colors` parameter propagate to the ParticleSystem. Previously the color list was only read at initState, so rebuilt widgets kept emitting particles with the original colors (fixes funwithflutter#102).
❌ Deploy Preview for dazzling-euclid-7da31e failed.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Fixes flutter_confetti #102 — updating the
colorsparameter of aConfettiWidgethas no effect.When the widget is rebuilt with a different
colorslist (e.g. viasetStatein the parent), the emitted confetti keeps using the original colors. Two root causes:_ConfettiWidgetStatenever implementeddidUpdateWidget, so the new color list was simply ignored.ParticleSystemstored the colors in afinalfield read once at construction, so there was no way to update it even if the state noticed the change.The only workaround available to users was forcing a full widget recreation via a
Keyderived from the color value (as noted in the issue).What changed
lib/src/confetti.dart—_ConfettiWidgetStatenow implementsdidUpdateWidget: whenwidget.colorsdiffers fromoldWidget.colors, the new list is forwarded to theParticleSystem.lib/src/particle.dart—_colorsis no longerfinal; added acolorssetter so the emission colors can be updated at runtime.test/confetti_test.dart— added 3 tests:ParticleSystememits particles with the color set through the setter.ConfettiWidgetrebuilds with a differentcolorslist without errors.Behavior notes
colorsparameter is handled for now — it's the only one whose change the issue reports, and the only one that can be updated safely without affecting in-flight particle physics.How I tested
flutter test— all tests pass (existing + 3 new).Built a local test app with the exact reproduction sample from the issue (blue square, "Toggle Color" / "Play" / "Pause" buttons,
colors: [_particleColor]) wired to this branch via a path dependency, and ran it on Chrome:ConfettiWidgetrebuild).On the released 0.8.0 code the same steps emit blue confetti, matching the issue's video.