Remove unnecessary Material imports from non-Material tests in flutter package#185271
Conversation
There was a problem hiding this comment.
Code Review
This pull request removes Material library dependencies from several tests by replacing MaterialApp with TestWidgetsApp, updating imports to widgets.dart, and substituting Material-specific constants like colors and selection controls with hardcoded values or generic alternatives. Feedback was provided regarding an inconsistent hex color value used for blue in editable_text_test.dart.
|
Tagging @justinmc and @navaronbracke for review — this consolidates the Material-import cleanups per @navaronbracke's suggestion on #185238, and is part of the cross-import effort in #177028 / #177412. |
c93d48b to
0d04159
Compare
0d04159 to
c435f7d
Compare
| style: const TextStyle(fontSize: 10.0), | ||
| cursorColor: Colors.blue, | ||
| backgroundCursorColor: Colors.grey, | ||
| cursorColor: const Color(0xFF2196F3), |
There was a problem hiding this comment.
Nit: Since this is reused, maybe we can define a global const here? This will make it slightly easier to read.
There was a problem hiding this comment.
Alright, makes sense. I'll address this.
There was a problem hiding this comment.
Yeah I think that's what other people have done when migrating these tests off of Color.
c435f7d to
fc18fa4
Compare
346f3ce to
2450cb8
Compare
|
Heads-up @navaronbracke @justinmc @victorsanni — I dropped two files from this PR because neither is a clean Material → widgets swap:
What's the preferred path forward — follow-up PRs with real fixes, stubs/workarounds, or leaving these in the allowlist? I can file tracking issues if that helps. |
2450cb8 to
072a369
Compare
victorsanni
left a comment
There was a problem hiding this comment.
Hi @momshaddinury, can you fix the failing linux analyze CI check?
06671b7 to
de04920
Compare
Where these tests previously used Colors.X, the cleanup PR that removed the Material import substituted the literal value of each constant (e.g. 0xFFF44336 for Colors.red). For tests that don't assert exact RGB values, pure-color hex codes (0xFFFF0000, etc.) are clearer about intent. - painting/star_border_test.dart: green 4CAF50 -> 00FF00 - widgets/default_text_editing_shortcuts_test.dart: blue 2196F3 -> 0000FF In default_text_editing_shortcuts_test.dart, also extract the cursor and background-cursor colors into top-level private consts (_cursorColor, _backgroundCursorColor) so the values are defined once and reused across all three EditableText sites. Also re-run `dart format` on the file, which collapses the two `testWidgets(...)` calls in the `Linux numpad shortcuts` group from the older multi-line style to the inline style. These are formatting changes only, no behavior changes. They surface because the format check validates files in the PR diff against the current dart_style version. Part of flutter#177028
There was a problem hiding this comment.
LGTM
@momshaddinury I had to review this with whitespace changes hidden, but that is because the formatting thing you explained in #185271 (comment) right?
Yes |
|
@navaronbracke @justinmc @victorsanni I am afraid there won't be anything to merge after a while. Already down to two files from 6. :3 |
|
@Piinks It's passing all the tests. Good to merge? |
|
@Piinks let me know if anything else is needed before it gets merged. All checks have passed. Thanks. |
Yes, and my reply was that both can be added to this PR. |
Several tests under
packages/flutter/test/were importingpackage:flutter/material.darteven though they only exercise APIs frompackage:flutter/widgets.dart(or lower layers likepainting,animation,gestures). Pulling in Material unnecessarily increases cross-package coupling between these tests and the Material library and works against the cross-import hygiene enforced bydev/bots/check_tests_cross_imports.dart.This PR:
package:flutter/material.darttopackage:flutter/widgets.dartin tests that do not reference any Material symbols.Colors.*only, replaces those with the equivalent rawconst Color(0x…)values.MaterialApppurely as aDirectionality/MediaQuery/localization host, swapsMaterialAppforTestWidgetsAppfromwidgets_app_tester.dart, and replacesmaterialTextSelectionControlswithemptyTextSelectionControls.check_tests_cross_imports.dartallowlist where applicable.No production code is modified and no test semantics change — the tests exercise the same widget/painting/gesture/animation behavior, just without dragging in Material.
Files changed
Tests updated:
packages/flutter/test/gestures/force_press_test.dartpackages/flutter/test/gestures/transformed_scale_test.dartpackages/flutter/test/widgets/default_text_editing_shortcuts_test.dartpackages/flutter/test/widgets/semantics_owner_test.dartpackages/flutter/test/animation/animation_sheet_test.dartpackages/flutter/test/painting/star_border_test.dartpackages/flutter/test/painting/paint_image_test.dartAllowlist updated:
dev/bots/check_tests_cross_imports.dartScope note — two files intentionally left out
Two test files originally staged in this cleanup were dropped after local test runs showed they aren't a clean Material → widgets swap. Details and a request for guidance are in a separate PR comment below:
packages/flutter/test/widgets/editable_text_scribe_test.dart— the handle-tap tests rely onCustomPaintwidgets painted bymaterialTextSelectionControls;emptyTextSelectionControlspaints nothing, so the handle finders return 0 widgets.packages/flutter/test/widgets/editable_text_test.dart(Live Text test only) — swappingMaterialApp→TestWidgetsApptriggersA FocusManager was used after being disposedin the sharedtearDown, cascading into five downstream a11y/semantics tests.Both files remain on the
check_tests_cross_imports.dartallowlist and can be picked up in follow-up PRs once we agree on the approach.Related issues
Context — why one PR
Per reviewer guidance from @navaronbracke on #185238 (comment), similar Material-import cleanups are being consolidated into a single PR that lands closer to the ~300–500-line "sweet spot" rather than as many tiny per-file PRs.
Superseded PRs (please close once this lands)
The following open PRs are subsumed by this one and can be closed if this PR is approved (see this comment):
Not superseded (corresponding files were dropped from this PR — see the scope note above):
Pre-launch Checklist
///).