[英]How to tests the constraints of a specific widget?
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
.我在屏幕 (
MyScreen
) 中有一个小部件 ( MyWidget
),我想编写一个测试来验证是否将特定约束应用于MyWidgets
。
How can I do that?我怎样才能做到这一点?
You can use tester.renderObject()
to obtain the RenderObject
and get the constraints from it:您可以使用
tester.renderObject()
来获取RenderObject
并从中获取约束:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.