feat(state): add context.select for granular page-scoped reads#1058
Merged
Conversation
Adds `context.select<T, R>(selector)` to `ModularStateX` — the method-based twin of the existing `Selector` widget, mirroring `context.select` from `provider` to ease migration. The calling widget rebuilds only when the selected value changes (`==`), instead of on every notification. To support per-dependent selection over a page-scoped value, `_VMInherited` now uses a custom `InheritedElement` that reproduces `InheritedNotifier`'s trigger-driven rebuilds while honoring per-dependent selector aspects (a `watch` dependent — no aspect — is still notified on every trigger). Bumps flutter_modular to 7.0.2 and documents the API in the README and the v7 state-management page. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Re-embeds the state-management page documenting `context.select<T, R>` and bumps the server version to 0.2.2 (pubspec + serverVersion handshake). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Adds
context.select<T, R>(selector)toModularStateX— the method-based twin of the existingSelectorwidget. It mirrorscontext.selectfrom provider to make migration a near drop-in.The calling widget rebuilds only when the selected value changes (
==), instead of on every notification (which is whatcontext.watchdoes).Why
We already ship
Consumer/Selector(provider-style widgets).context.selectrounds out the migration surface so projects coming fromprovidercan move method-by-method without restructuring their widget trees.How
A plain
InheritedNotifiernotifies every dependent on each trigger, so it can't do per-widget selection on its own._VMInheritednow uses a customInheritedElementthat:InheritedNotifier's trigger-driven rebuild behavior, andA
watchdependent (no aspect) is still notified on every trigger, sowatch/read/Consumer/Selectorbehavior is unchanged.Tests
test/select_test.dart: rebuilds only on selected change, ignores unrelated changes, keeps tracking across rebuilds, and throws when no scopedTis provided.flutter analyzeclean.Notes
flutter_modularto 7.0.2 (README + CHANGELOG + v7 state-management docs updated).tool/docs_mcp), binary recompiled & smoke-tested locally.🤖 Generated with Claude Code