Skip to content

fix: notify listeners on setConfiguration and setTextDirection changes#1165

Open
menna3lwan wants to merge 1 commit into
bosskmk:masterfrom
menna3lwan:fix/grid-configuration-notify
Open

fix: notify listeners on setConfiguration and setTextDirection changes#1165
menna3lwan wants to merge 1 commit into
bosskmk:masterfrom
menna3lwan:fix/grid-configuration-notify

Conversation

@menna3lwan

Copy link
Copy Markdown

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.

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.
Copilot AI review requested due to automatic review settings July 9, 2026 11:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and setTextDirection() (deferred via post-frame) with an opt-out notify flag.
  • 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants