Skip to content

(Test cross-imports) Don't import Material in tests for convenience #177415

Open
1 of 1 issue completed
Open

Description

@justinmc

Umbrella issue: #177028
Design doc: https://docs.google.com/document/d/1UHxALQqCbmgjnM1RNV9xE2pK3IGyx-UktGX1D7hYCjs/edit?tab=t.0

Tests shouldn't import the Material library simply out of convenience (such as to use MaterialApp instead of WidgetsApp). This will help with our general test organization and also help remove a devDependency after Material and Cupertino are decoupled from the framework.

How to fix

The tests listed below import Material when they shouldn't, typically to access something like MaterialApp. Don't just move these tests into the Material library. They should stay in the library of the file that they are testing.

  1. Find a test listed below that is not already fixed (checked) and that does not have a PR already linked.
  2. Replace the "convenient" widget imported from another library with something in the current library. If needed, create a helper to make it easier to accomplish the same thing in tests.
  3. When you open a PR, reference this issue as "Part of " instead of "Fixes", to avoid it being prematurely closed.
Widget What to do
Material This is probably used to wrap widgets that require a Material ancestor. If possible, just remove it, or replace it with something like Container. If not possible, consider replacing or removing the widget that depends on its presence.
MaterialApp @rkishan516 has created a TestWidgetsApp in #180506 to easily replace MaterialApp.
Colors Replace with Color and a hex value. Per offline discussion with @victorsanni, consider creating a utils file with convenient color constants, but only in the tests. Use prefixed names like debugRed, etc., to avoid collisions if used with static extensions and dot shorthands in the future. For colors that vary by index, like in a list, use getTestColors, added by @navaronbracke in #180994.
ListTile Use TestListTile, added by @huycozy in #180572.
Icons Remove if possible.
ElevatedButton Use TestButton, created by @navaronbracke in #180994.
Checkbox If it can't be removed, replace it with buildToggleable, and/or we should create a TestCheckbox or RawCheckbox.
MaterialPageRoute Use PageRouteBuilder.
Divider Remove it altogether if possible, otherwise use something like SizedBox. See @navaronbracke's work in #180999.
TextField Use TestTextField once #180494 is merged (thanks @Renzo-Olivares ).

Tests to fix:

Located in Widgets, imported Material

Located in Cupertino, imported Material

Activity

  1. added
    in triagePresently being triaged by the triage team
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Oct 23, 2025
  2. rkishan516 commented on Oct 25, 2025

    @rkishan516
    Contributor

    @justinmc Can i help in fixing some of test files?

  3. self-assigned this
    on Oct 28, 2025
  4. justinmc commented on Oct 28, 2025

    @justinmc
    ContributorAuthor

    @rkishan516 Thank you for jumping in to offer help! Can you hold off for another day or two first though? I want to get approval on my design doc first to make sure everyone is on board with this cleanup. Feel free to comment on there if you have any thoughts.

    I'm assigning myself to these issues for now to signal that no one should work on them, but I'll unassign myself when it's approved.

    There are over 200 tests to fix so I'm going to need help, thanks again for offering!

  5. added
    P1High-priority issues at the top of the work list
    on Oct 28, 2025
  6. rkishan516 commented on Oct 29, 2025

    @rkishan516
    Contributor

    Sounds good! I'll hold off until the design doc is approved. Just let me know when you're ready - happy to help tackle those tests!

  7. moved this to In Progress in Decoupling Designon Nov 5, 2025
  8. justinmc commented on Jan 2, 2026

    @justinmc
    ContributorAuthor

    Alright these are up for contributions now that #177029 and #178693 have merged! FYI @rkishan516 and anyone else that might want to help. Same goes for the rest of the tests under the umbrella issue (#177028).

    For these in particular, check the table at the top about how to migrate certain widgets. We probably want to create a few helper widgets or something like that in a utils file in test/widgets.

    Unassigning myself.

  9. 235 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work lista: tests"flutter test", flutter_test, or one of our testsc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions