0

I have a widget (MyWidget) in a screen (MyScreen) and I would like to write a test that verifies that specific constraints are applied to MyWidgets.

How can I do that?

Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73

1 Answers1

0

You can use tester.renderObject() to obtain the RenderObject and get the constraints from it:

await tester.pumpWidget(const MyScreen());

final renderObject = tester.renderObject(find.byType(MyWidget));
final constraintsMatcher = BoxConstraints(maxHeight: 200); // For example, it can be any matcher.
expect(renderObject.constraints, constraintsMatcher); 
Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73