Skip to content

Remove unused material.dart import from force_press_test.dart#185236

Closed
momshaddinury wants to merge 1 commit into
flutter:masterfrom
momshaddinury:test/remove-unused-material-import-force-press
Closed

Remove unused material.dart import from force_press_test.dart#185236
momshaddinury wants to merge 1 commit into
flutter:masterfrom
momshaddinury:test/remove-unused-material-import-force-press

Conversation

@momshaddinury
Copy link
Copy Markdown
Contributor

This PR removes a single unused import 'package:flutter/material.dart'; from packages/flutter/test/gestures/force_press_test.dart. The test file does not reference any symbols from the Material library — no MaterialApp, Theme, Colors, widgets, or any other Material API is used anywhere in the file. The import is leftover noise and contributes unnecessarily to the cross-package coupling that issue #177412 is tracking.

This is a mechanical, behavior-preserving cleanup. No test logic, no production code, and no public API is touched. The existing test continues to exercise the same gesture recognizer behavior and passes unchanged.

Fixes part of #177412 (one file; the issue tracks a broader cleanup across many test files).

No screenshots are applicable — this is a single-line deletion in a test file.

AI tool disclosure

Per the AI contribution guidelines: Claude (Anthropic) was used to help identify candidate files (unused package:flutter/material.dart imports in tests where no Material symbols appear) and to assist with authoring this PR description. I reviewed the change manually, verified no Material references exist in the file, and ran the analyzer and the affected test locally before pushing.

Pre-launch Checklist

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: gestures flutter/packages/flutter/gestures repository. labels Apr 18, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes an unused import of the material library from the force_press_test.dart file. I have no feedback to provide.

@momshaddinury momshaddinury force-pushed the test/remove-unused-material-import-force-press branch from 31eb28c to 90b9d6c Compare April 20, 2026 06:53
@momshaddinury
Copy link
Copy Markdown
Contributor Author

Referencing this feedback, let me know if I need to remove imports from any CI check. I have checked the dev/bots/check_tests_cross_imports.dart file, and didn't find a reference to the packages/flutter/test/gestures/force_press_test.dart file.

The test file does not reference any Material symbols. Removing this
unused import reduces unnecessary cross-package coupling between the
gestures test and the Material library.

Issue: flutter#177412
@momshaddinury momshaddinury force-pushed the test/remove-unused-material-import-force-press branch from 90b9d6c to 5bf36fb Compare April 20, 2026 06:58

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@justinmc I wonder, is the check in https://github.com/flutter/flutter/blob/master/dev/bots/check_tests_cross_imports.dart not strict enough?

This file had a cross import from flutter/material in flutter/test/gestures (which is similar to flutter/test/widgets in terms of namespace)

@momshaddinury
Copy link
Copy Markdown
Contributor Author

Closing this in favour of #185271.

pull Bot pushed a commit to NOUIY/flutter that referenced this pull request May 21, 2026
…r package (flutter#185271)

Several tests under `packages/flutter/test/` were importing
`package:flutter/material.dart` even though they only exercise APIs from
`package:flutter/widgets.dart` (or lower layers like `painting`,
`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 by
`dev/bots/check_tests_cross_imports.dart`.

This PR:

- Switches the import from `package:flutter/material.dart` to
`package:flutter/widgets.dart` in tests that do not reference any
Material symbols.
- Where tests referenced `Colors.*` only, replaces those with the
equivalent raw `const Color(0x…)` values.
- Where tests wrapped widgets in `MaterialApp` purely as a
`Directionality`/`MediaQuery`/localization host, swaps `MaterialApp` for
`TestWidgetsApp` from `widgets_app_tester.dart`, and replaces
`materialTextSelectionControls` with `emptyTextSelectionControls`.
- Removes the corresponding entry from the
`check_tests_cross_imports.dart` allowlist 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.dart`
- `packages/flutter/test/gestures/transformed_scale_test.dart`
-
`packages/flutter/test/widgets/default_text_editing_shortcuts_test.dart`
- `packages/flutter/test/widgets/semantics_owner_test.dart`
- `packages/flutter/test/animation/animation_sheet_test.dart`
- `packages/flutter/test/painting/star_border_test.dart`
- `packages/flutter/test/painting/paint_image_test.dart`

Allowlist updated:

- `dev/bots/check_tests_cross_imports.dart`

## Scope 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 on `CustomPaint` widgets painted by
`materialTextSelectionControls`; `emptyTextSelectionControls` paints
nothing, so the handle finders return 0 widgets.
- `packages/flutter/test/widgets/editable_text_test.dart` (Live Text
test only) — swapping `MaterialApp` → `TestWidgetsApp` triggers `A
FocusManager was used after being disposed` in the shared `tearDown`,
cascading into five downstream a11y/semantics tests.

Both files remain on the `check_tests_cross_imports.dart` allowlist and
can be picked up in follow-up PRs once we agree on the approach.

## Related issues

- Part of umbrella issue flutter#177028 (Framework unit tests
shouldn't cross-import libraries).
- Also addresses flutter#177412 (No legacy Material imports in
tests).

## Context — why one PR

Per reviewer guidance from @navaronbracke on flutter#185238
([comment](flutter#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](flutter#185238 (comment))):

- flutter#185236 — Remove unused material.dart import from
force_press_test.dart
- flutter#185241 — Remove unnecessary Material import from
default_text_editing_shortcuts_test

Not superseded (corresponding files were dropped from this PR — see the
scope note above):

- flutter#185238 — editable_text_scribe_test
- flutter#185242 — editable_text_test Live Text

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt]. <!-- test-only cleanup: no production code or
test-behavior changes; existing coverage is preserved. -->
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
matthewhendrix pushed a commit to matthewhendrix/flutter that referenced this pull request May 23, 2026
…r package (flutter#185271)

Several tests under `packages/flutter/test/` were importing
`package:flutter/material.dart` even though they only exercise APIs from
`package:flutter/widgets.dart` (or lower layers like `painting`,
`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 by
`dev/bots/check_tests_cross_imports.dart`.

This PR:

- Switches the import from `package:flutter/material.dart` to
`package:flutter/widgets.dart` in tests that do not reference any
Material symbols.
- Where tests referenced `Colors.*` only, replaces those with the
equivalent raw `const Color(0x…)` values.
- Where tests wrapped widgets in `MaterialApp` purely as a
`Directionality`/`MediaQuery`/localization host, swaps `MaterialApp` for
`TestWidgetsApp` from `widgets_app_tester.dart`, and replaces
`materialTextSelectionControls` with `emptyTextSelectionControls`.
- Removes the corresponding entry from the
`check_tests_cross_imports.dart` allowlist 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.dart`
- `packages/flutter/test/gestures/transformed_scale_test.dart`
-
`packages/flutter/test/widgets/default_text_editing_shortcuts_test.dart`
- `packages/flutter/test/widgets/semantics_owner_test.dart`
- `packages/flutter/test/animation/animation_sheet_test.dart`
- `packages/flutter/test/painting/star_border_test.dart`
- `packages/flutter/test/painting/paint_image_test.dart`

Allowlist updated:

- `dev/bots/check_tests_cross_imports.dart`

## Scope 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 on `CustomPaint` widgets painted by
`materialTextSelectionControls`; `emptyTextSelectionControls` paints
nothing, so the handle finders return 0 widgets.
- `packages/flutter/test/widgets/editable_text_test.dart` (Live Text
test only) — swapping `MaterialApp` → `TestWidgetsApp` triggers `A
FocusManager was used after being disposed` in the shared `tearDown`,
cascading into five downstream a11y/semantics tests.

Both files remain on the `check_tests_cross_imports.dart` allowlist and
can be picked up in follow-up PRs once we agree on the approach.

## Related issues

- Part of umbrella issue flutter#177028 (Framework unit tests
shouldn't cross-import libraries).
- Also addresses flutter#177412 (No legacy Material imports in
tests).

## Context — why one PR

Per reviewer guidance from @navaronbracke on flutter#185238
([comment](flutter#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](flutter#185238 (comment))):

- flutter#185236 — Remove unused material.dart import from
force_press_test.dart
- flutter#185241 — Remove unnecessary Material import from
default_text_editing_shortcuts_test

Not superseded (corresponding files were dropped from this PR — see the
scope note above):

- flutter#185238 — editable_text_scribe_test
- flutter#185242 — editable_text_test Live Text

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt]. <!-- test-only cleanup: no production code or
test-behavior changes; existing coverage is preserved. -->
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

Development

Successfully merging this pull request may close these issues.

3 participants