Skip to content

Remove Material Dependency from semantics_debugger_test#181722

Closed
rizwan-saleem wants to merge 12 commits into
flutter:masterfrom
rizwan-saleem:fix-material-import-semantics-debugger
Closed

Remove Material Dependency from semantics_debugger_test#181722
rizwan-saleem wants to merge 12 commits into
flutter:masterfrom
rizwan-saleem:fix-material-import-semantics-debugger

Conversation

@rizwan-saleem

@rizwan-saleem rizwan-saleem commented Jan 30, 2026

Copy link
Copy Markdown

This change refactors semantics_debugger_test.dart to eliminate its dependency on Material widgets, as part of the test reorganization effort to ensure tests only depend on the library code they are testing.


Changes

  • Replace Material import with widgets import in semantics_debugger_test.dart
  • Replace ElevatedButton with TestButton (2 tests)
  • Replace Slider with TestSlider (1 test)
  • Replace Checkbox with TestCheckbox (2 tests)
  • Replace TextField with TestTextField (1 test)
  • Replace MaterialApp with TestWidgetsApp (2 tests)
  • Remove Material wrapper widgets throughout tests
  • Replace Colors constants with explicit Color values

New Test Widgets Created

TestSlider

A minimal slider with semantics support for testing.

  • Implements onIncrease / onDecrease semantic actions
  • Supports min/max range and divisions
  • Uses a 10% adjustment unit for continuous sliders

TestCheckbox

A minimal checkbox with semantics support for testing.

  • Implements checked state and onTap semantic action
  • Supports enabled and disabled states

Enhanced Existing Test Widget

TestTextField

Updated to better match the Material TextField semantics structure.

  • Added a Semantics wrapper
  • Provides enabled state and onTap action
  • Allows tests to find Semantics descendants as expected

Test Results

All 21 tests pass successfully with the new test widget
Part of #177414

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

talabat.com contributions Talabat Flutter PRs

This change refactors `semantics_debugger_test.dart` to eliminate its dependency on **Material** widgets, as part of the test reorganization effort to ensure tests only depend on the library code they are testing.

---

## Changes

- Replace `Material` import with `widgets` import in `semantics_debugger_test.dart`
- Replace `ElevatedButton` with `TestButton` (2 tests)
- Replace `Slider` with `TestSlider` (1 test)
- Replace `Checkbox` with `TestCheckbox` (2 tests)
- Replace `TextField` with `TestTextField` (1 test)
- Replace `MaterialApp` with `TestWidgetsApp` (2 tests)
- Remove `Material` wrapper widgets throughout tests
- Replace `Colors` constants with explicit `Color` values

---

## New Test Widgets Created

### `TestSlider`
A minimal slider with semantics support for testing.

- Implements `onIncrease` / `onDecrease` semantic actions
- Supports min/max range and divisions
- Uses a **10% adjustment unit** for continuous sliders

### `TestCheckbox`
A minimal checkbox with semantics support for testing.

- Implements checked state and `onTap` semantic action
- Supports enabled and disabled states

---

## Enhanced Existing Test Widget

### `TestTextField`
Updated to better match the Material `TextField` semantics structure.

- Added a `Semantics` wrapper
- Provides enabled state and `onTap` action
- Allows tests to find `Semantics` descendants as expected

---

## Test Results

All **21 tests pass** successfully with the new test widget
@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) labels Jan 30, 2026

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

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.

Code Review

This pull request successfully refactors semantics_debugger_test.dart to eliminate its dependency on Material widgets, which is a great improvement for test modularity. The introduction of minimal test widgets like TestSlider and TestCheckbox is well-executed. My review includes a few suggestions to simplify the implementation of these new test widgets by removing some redundant null checks, which will improve code conciseness.

Comment thread packages/flutter/test/widgets/utils.dart Outdated
Comment thread packages/flutter/test/widgets/utils.dart Outdated
Comment thread packages/flutter/test/widgets/utils.dart Outdated
@rizwan-saleem

Copy link
Copy Markdown
Author

@justinmc can you please review the changes in the PR to eliminate its dependency on Material widgets ?

@justinmc justinmc left a comment

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.

Thanks for jumping in and helping here! This wasn't a super easy one but I think you just about got it.

showCursor: widget.showCursor,
style: widget.style ?? const TextStyle(), // required by editable text.
controller: _effectiveController, // required by editable text.
return Semantics(

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.

Are you able to do this via EditableText which has a Semantics inside of it? @Renzo-Olivares I wonder what you think about this.

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.

@Renzo-Olivares pointed out to me that EditableText actually does not have onTap in its Semantics:

child: Semantics(
inputType: inputType,
onCopy: _semanticsOnCopy(controls),
onCut: _semanticsOnCut(controls),
onPaste: _semanticsOnPaste(controls),
child: _ScribbleFocusable(

That is handled in TextField and in CupertinoTextField. We should probably move that semantics logic to EditableText, but after this PR. I'll create an issue.

In the meantime, I think we should move the test "SemanticsDebugger textfield" to material, and keep TestTextField as-is.

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.

Issue: #181873

@rizwan-saleem When you move the test to Material, please add a TODO that references this issue.

/// This widget provides minimal slider functionality without depending on
/// Material Design components. It only handles semantic actions for testing
/// purposes and does not render any visual elements.
class TestSlider extends StatelessWidget {

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.

Can you add a TODO like this for each of these two new Test classes you wrote?

// TODO(rkishan516): Move this to flutter_test package.
// Tracking issue: https://github.com/flutter/flutter/issues/181283

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.

Also, I think we should move these classes to their own files, like slider_tester.dart and checkbox_tester.dart. I should probably move TestButton in another PR too, sorry for the misleading example here.

CC @Renzo-Olivares for thoughts.

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.

Sounds good to me!

2000.0,
warnIfMissed: false,
); // hitting the debugger
switch (defaultTargetPlatform) {

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.

This test looks like it's testing some specific platform logic based on this switch. I wonder if we should duplicate it in Material.

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.

Good catch, yes I would copy the original test to Material and keep the version you have now here.

Directionality(
textDirection: TextDirection.ltr,
child: SemanticsDebugger(
child: Material(

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.

I think this test might also be a good candidate to duplicate or outright move to Material since it seems to be specifically testing Checkbox and not just the general functionality.

Unlike SemanticsDebugger interaction test earlier in this file which uses the buttons as a means to add logs to a list, this is testing the Checkbox functionality.

textDirection: TextDirection.ltr,
child: SemanticsDebugger(
key: debugger,
child: Material(

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.

@rizwan-saleem

Copy link
Copy Markdown
Author

Thank you @justinmc @Renzo-Olivares for all the valuable comments on the PR. It really helped to understand how things need to be done for other cross import files too.

I will tag you guys again once I have made the changes. 🙏

github-merge-queue Bot pushed a commit that referenced this pull request Feb 14, 2026
…" (#182406)

<!-- start_original_pr_link -->
Reverts: #182395
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: gaaclarke
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: this is causing breakages on the dashboard

example:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8689933991528003217/+/u/run_test.dart_for_framework_tests_shard_and_subshard_libraries/stdout

```
10:36 +9458 ~24: /b/s/w/ir/x/w/flutter/packages/flutter/test/material/dialog_test.dart: Dialog children padding is correct AlertDialog padding is correct when only icon, title a
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: justinmc
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {Renzo-Olivares, victorsanni, navaronbracke}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
This PR moves:

 * TestTextField from editable_text_utils.dart to editable_text_tester.dart
 * TestListTile from list_tile_test_utils.dart to list_tile_tester.dart
 * TestButton from utils.dart to button_tester.dart
 
The purpose is to align with other Test* widgets, such as TestWidgetsApp in [widgets_app_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/widgets_app_tester.dart) and TestSemantics in [semantics_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/semantics_tester.dart).

We should continue to follow this pattern in the future, such as in #181722.
<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <[email protected]>
@justinmc justinmc moved this from Todo to Done in Test cross-imports Review Queue Feb 19, 2026
@justinmc justinmc moved this from Done to In Progress in Test cross-imports Review Queue Feb 19, 2026
rickhohler pushed a commit to rickhohler/flutter that referenced this pull request Feb 19, 2026
…#182395)" (flutter#182406)

<!-- start_original_pr_link -->
Reverts: flutter#182395
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: gaaclarke
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: this is causing breakages on the dashboard

example:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8689933991528003217/+/u/run_test.dart_for_framework_tests_shard_and_subshard_libraries/stdout

```
10:36 +9458 ~24: /b/s/w/ir/x/w/flutter/packages/flutter/test/material/dialog_test.dart: Dialog children padding is correct AlertDialog padding is correct when only icon, title a
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: justinmc
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {Renzo-Olivares, victorsanni, navaronbracke}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
This PR moves:

 * TestTextField from editable_text_utils.dart to editable_text_tester.dart
 * TestListTile from list_tile_test_utils.dart to list_tile_tester.dart
 * TestButton from utils.dart to button_tester.dart
 
The purpose is to align with other Test* widgets, such as TestWidgetsApp in [widgets_app_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/widgets_app_tester.dart) and TestSemantics in [semantics_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/semantics_tester.dart).

We should continue to follow this pattern in the future, such as in flutter#181722.
<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <[email protected]>
@Renzo-Olivares

Copy link
Copy Markdown
Contributor

Hi @rizwan-saleem, just checking in on how it's going with this pull request. Let me know if you have any questions, happy to help!

Comment on lines +9 to +10
// TODO(rizwan-saleem): Move this to material package.
// Tracking issue: https://github.com/flutter/flutter/issues/177414

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.

Was this added by mistake or am I misunderstanding? Seems like this file is in the right spot.

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.

I think maybe you misread my comment (#181722 (comment)). I meant that you should move this test into test/material/semantics_debugger_test.dart, and then add a comment with a TODO linking to #181873.

I think this test is fundamentally testing logic that is currently inside of TextField in the Material library, so the test should go in the Material library tool.

@justinmc

Copy link
Copy Markdown
Contributor

@rizwan-saleem Are you still planning to return to this PR and get it ready to merge?

@rizwan-saleem

rizwan-saleem commented Mar 15, 2026

Copy link
Copy Markdown
Author

@justinmc sorry for the delay, I am on it, finishing the work this weekend

# Conflicts:
#	dev/bots/check_tests_cross_imports.dart
#	packages/flutter/test/widgets/editable_text_utils.dart
@github-actions github-actions Bot removed the a: text input Entering text in a text field or keyboard related problems label Mar 15, 2026
The `SemanticsDebugger` tests for `Slider`, `Checkbox`, and `TextField` have been moved from the `widgets` package to the `material` package. This change ensures that tests for Material-specific implementations of these widgets are located alongside their respective package.
@github-actions github-actions Bot added the f: material design flutter/packages/flutter/material repository. label Mar 18, 2026
@dkwingsmt dkwingsmt added the CICD Run CI/CD label Mar 25, 2026
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…#182395)" (flutter#182406)

<!-- start_original_pr_link -->
Reverts: flutter#182395
<!-- end_original_pr_link -->
<!-- start_initiating_author -->
Initiated by: gaaclarke
<!-- end_initiating_author -->
<!-- start_revert_reason -->
Reason for reverting: this is causing breakages on the dashboard

example:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8689933991528003217/+/u/run_test.dart_for_framework_tests_shard_and_subshard_libraries/stdout

```
10:36 +9458 ~24: /b/s/w/ir/x/w/flutter/packages/flutter/test/material/dialog_test.dart: Dialog children padding is correct AlertDialog padding is correct when only icon, title a
<!-- end_revert_reason -->
<!-- start_original_pr_author -->
Original PR Author: justinmc
<!-- end_original_pr_author -->

<!-- start_reviewers -->
Reviewed By: {Renzo-Olivares, victorsanni, navaronbracke}
<!-- end_reviewers -->

<!-- start_revert_body -->
This change reverts the following previous change:
This PR moves:

 * TestTextField from editable_text_utils.dart to editable_text_tester.dart
 * TestListTile from list_tile_test_utils.dart to list_tile_tester.dart
 * TestButton from utils.dart to button_tester.dart
 
The purpose is to align with other Test* widgets, such as TestWidgetsApp in [widgets_app_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/widgets_app_tester.dart) and TestSemantics in [semantics_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/semantics_tester.dart).

We should continue to follow this pattern in the future, such as in flutter#181722.
<!-- end_revert_body -->

Co-authored-by: auto-submit[bot] <[email protected]>
@dkwingsmt

Copy link
Copy Markdown
Contributor

Here's a reminder that there are still analyzer issues. (from triage)

@chunhtai chunhtai added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 22, 2026
# Conflicts:
#	dev/bots/check_tests_cross_imports.dart
#	packages/flutter/test/widgets/checkbox_tester.dart
#	packages/flutter/test/widgets/semantics_debugger_test.dart
@github-actions github-actions Bot removed CICD Run CI/CD waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds labels Apr 25, 2026
@rizwan-saleem

Copy link
Copy Markdown
Author

All comments addressed. Code freeze check is there
cc. @dkwingsmt

@rizwan-saleem

Copy link
Copy Markdown
Author

Closing this PR, as semantics_debugger_test is handled in another PR.

@github-project-automation github-project-automation Bot moved this from In Progress to Done in Test cross-imports Review Queue Apr 25, 2026
@rizwan-saleem rizwan-saleem deleted the fix-material-import-semantics-debugger branch April 25, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

Development

Successfully merging this pull request may close these issues.

6 participants