feat(mix): complete widget modifier config APIs - #1054
Merged
Merged
Conversation
Add `mouseCursor` and `scrollView` as both `WidgetModifierConfig` factories and chain methods, and add the chain methods their factories were missing for `skew`, `defaultIcon`, `iconTheme`, `box`, and `reset`. Every built-in modifier is now reachable without `.modifier(SomeModifierMix(...))`, while `modifier`/`modifiers` stay the entry points for custom modifiers. All new members delegate to the existing factories and `merge`, so modifier ordering, merge keys, null handling, rendering, and animation are unchanged. Chained `reset()` collapses to an empty modifier list, so it clears only the modifiers accumulated in that configuration; the `WidgetModifierConfig.reset()` factory is still required when the reset must survive a later merge. Both behaviors are characterized in tests and documented on the method. Remove guides/modifier-config-api-plan.md now that the plan is implemented.
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.
Related issue
None. Implements the proposal from #1053, which this PR supersedes.
Description
Every built-in modifier now has both a
WidgetModifierConfigfactory and a matching fluent chain method, so callers no longer need.modifier(SomeModifierMix(...))to reach a first-party modifier.modifier/modifiersremain the entry points for custom modifiers.The audit that motivated this found two kinds of gap:
mouseCursorscrollViewskewdefaultIconiconThemeboxresetPurely additive. Every new member delegates to an existing factory and
merge, so modifier ordering, merge keys, null/default handling, rendering, and animation behavior are unchanged. No existing signature changed and no consumer migration is needed.A note on
reset()The chained
reset()ismerge(WidgetModifierConfig.reset()), which collapses to an empty modifier list rather than retaining the reset marker. So it clears the modifiers accumulated in that configuration only — merging the result into another configuration no longer clears that one:That is pre-existing merge behavior, not something introduced here. It is characterized in tests and documented on the method, with a pointer to the factory for the merge-surviving case. Redesigning the reset algorithm was deliberately left out of scope.
Changes
packages/mix/lib/src/modifiers/widget_modifier_config.dart:mouseCursorandscrollViewfactories + chain methods; chain methods forskew,defaultIcon,iconTheme,box,reset. Dartdoc on the new entry points, with thereset()semantics spelled out.packages/mix/test/src/modifiers/widget_modifier_config_test.dart(new, 25 tests): factory ↔ explicit-modifier parity; full option forwarding forscrollViewandiconThemeincluding omitted-stays-null; chain ↔ merge parity; contextual dot shorthand through a Styler'swrap; same-type merge without duplication; source-configuration immutability; customorderOfModifierssurviving chaining; sixresetcharacterization tests. Two widget pumps assert the realMouseRegionandSingleChildScrollVieware produced.packages/mix/CHANGELOG.md: entry under the unreleased2.2.0-beta.5section.guides/api-composition-guidelines.md: quick-reference lines and a worked widget-modifier example. Both snippets were compiled against the package before being added.guides/modifier-config-api-plan.md: removed, now that the plan it described is implemented.Review Checklist
melos run gen:build(no generation drift),melos run analyze(Dart + DCM), andmelos run ciall pass.flutter test test/src/modifiersis green at 498 tests, 25 of them new..modifier(...)form until these APIs land in a published release.Additional Information (optional)
Pre-existing defect found while testing, deliberately not fixed here.
MouseCursorModifierandScrollViewModifierare absent from_defaultOrder, soreorderModifiersappends them in chaining order and always places them innermost:In practice
.scrollView(...).padding(...)puts the padding outside the scroll view, and the two modifiers' relative order depends on call order. This predates the PR, but it matters more now that both are first-class APIs. Related and also pre-existing: thedefaultModifierlerp-fallback map omitsMouseCursorModifier,ScrollViewModifier,ClipRectModifier,ShaderMaskModifier,DefaultTextStylerModifier, andBoxModifier, so animating those from absent to present snaps att = 0.5instead of lerping. Both are worth a separate follow-up.The branch name still carries the
docs/prefix from the plan-only branch this work grew out of; the change itself is afeat.