Skip to content

Make color property accessible when testing Container widgets #28753

@maryx

Description

@maryx

This is somewhat related to #15042 but it's more about the accessibility of color when testing a Container.

I have a StatelessWidget that in build() does return Container(color: Colors.black);

In my test I do:

testWidgets('Container is black.',
      (WidgetTester tester) async {
    await _setUp();
    final background = tester.firstWidget(find.byType(Container)) as Container;
    expect((background.decoration as BoxDecoration).color, Colors.black);
  });

It would be nice to do:

testWidgets('Container is black.',
      (WidgetTester tester) async {
    await _setUp();
    final background = tester.firstWidget(find.byType(Container)) as Container;
    expect(background.color, Colors.black);
  });

I was hoping that, as setting color is a shorthand, during testing, getting color would also be available (and it would look for the decoration property's color property for me).

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions