fix: notify listeners on setConfiguration and setTextDirection changes#1165
Open
menna3lwan wants to merge 1 commit into
Open
fix: notify listeners on setConfiguration and setTextDirection changes#1165menna3lwan wants to merge 1 commit into
menna3lwan wants to merge 1 commit into
Conversation
Both methods mutated internal state without calling notifyListeners(), so PlutoStateWithChange-based cells (icons, Select, Date) never rebuilt on their own after a configuration or RTL/LTR direction change - only when an unrelated event happened to force a rebuild. setTextDirection defers via notifyListenersOnPostFrame since it's invoked mid-build (PlutoGridLayoutDelegate's constructor), matching the existing pattern used by setKeepFocus.
There was a problem hiding this comment.
Pull request overview
This PR addresses a UI staleness issue in PlutoGridStateManager where internal state changes from setConfiguration() and setTextDirection() did not reliably trigger rebuilds in dependent widgets, especially during RTL/LTR and configuration changes.
Changes:
- Add listener notifications for
setConfiguration()(synchronous) andsetTextDirection()(deferred via post-frame) with an opt-outnotifyflag. - Add unit tests asserting notification behavior for both APIs.
- Update mock signatures and notifier name mappings to reflect the new APIs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/src/manager/state/layout_state_test.dart | Adds widget tests validating deferred notification behavior for setTextDirection. |
| test/src/manager/state/grid_state_test.dart | Adds tests validating setConfiguration notifies listeners (and respects equality/notify=false). |
| test/mock/shared_mocks.mocks.dart | Updates generated mocks for the new notify named parameters. |
| lib/src/manager/state/layout_state.dart | Adds notify parameter and post-frame notification for setTextDirection. |
| lib/src/manager/state/grid_state.dart | Adds notify parameter and listener notification for setConfiguration. |
| lib/src/manager/pluto_change_notifier_filter.dart | Adds notifier-name entries for setConfiguration and setTextDirection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _state._configuration!.applyColumnFilter(refColumns.originalList); | ||
| } | ||
|
|
||
| notifyListeners(notify, setConfiguration.hashCode); |
| // dependent widgets to rebuild while the widget tree above them is still | ||
| // being built, which Flutter disallows. Defer to the next frame instead, | ||
| // matching the pattern already used by setKeepFocus. | ||
| notifyListenersOnPostFrame(notify, setTextDirection.hashCode); |
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.
Root Cause
_Both setConfiguration() and setTextDirection() update the Grid's internal state, but neither method notified listeners after the state changed.
Many Grid components—especially cells that extend PlutoStateWithChange (such as Select, Date, and cells that display directional icons)—depend on notifyListeners() to know when they should rebuild.
As a result, when the Grid configuration or the RTL/LTR direction changed:_
The internal state was updated correctly.
The Cells were never notified about that update.
Therefore, they continued rendering using the previous configuration.
They only refreshed later if another unrelated action (such as selecting a cell, scrolling, or any event that triggered a rebuild) happened to call notifyListeners().
This created the impression that changing the application language did not fully update the Grid, even though the underlying configuration had already changed.
Solution
The fix ensures that every time the internal configuration changes, the Grid immediately notifies all dependent listeners so that every affected Cell rebuilds using the latest configuration.
Two different notification strategies are used because the two methods execute in different lifecycle stages.
setConfiguration()
setConfiguration() is called outside the widget build process, so it is safe to invoke:
notifyListeners();
immediately after updating the internal configuration.
This allows all dependent Cells to rebuild instantly using the new configuration.
setTextDirection()
setTextDirection() is different.
It is invoked during the widget build process from PlutoGridLayoutDelegate's constructor.
Calling notifyListeners() directly at that point would trigger Flutter's:
setState() or markNeedsBuild() called during build
assertion.
For that reason, the notification is deferred until the current frame finishes by using:
notifyListenersOnPostFrame();
This follows the exact same pattern already used by setKeepFocus(), making the implementation consistent with the existing architecture while avoiding build-time notifications.
Result
After this change:
Switching between RTL and LTR immediately updates every Grid Cell.
Select Cells rebuild correctly.
Date Cells rebuild correctly.
Directional icons are updated immediately.
No manual interaction is required to refresh the Grid.
Existing APIs and behavior remain unchanged.
The fix is centralized inside the Package and benefits every application that uses it.