我正在为我的应用程序写一些测试。目前,我正在测试抽屉。在各种大小的模拟器上,它运行没有问题(从240x432到1440x2960),但当我尝试运行一个简单的测试时,抛出了以下错误:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 188 pixels on the right.
The overflowing RenderFlex has an orientation of Axis.horizontal.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be
seen. If the content is legitimately bigger than the available space, consider clipping it with a
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#1ae2c relayoutBoundary=up17 OVERFLOWING:
creator: Row ← Center ← Padding ← Container ← IconTheme ← Builder ← Listener ← _GestureSemantics ←
RawGestureDetector ← GestureDetector ← Listener ← InkWell ← ⋯
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=256.0, 0.0<=h<=Infinity)
size: Size(256.0, 24.0)
direction: horizontal
mainAxisAlignment: start
mainAxisSize: min
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
字符串
在代码中,我将其缩小到一些RaisedButton
。当里面的Row
小于一定长度时,错误不会显示。
当我注解掉下面的代码时,所有测试都运行得没有问题。
Padding(
padding: EdgeInsets.symmetric(vertical: 32, horizontal: 16),
child: Column(
children: [
FacebookSignInButton(
onPressed: _fbLogin,
),
GoogleSignInButton(
onPressed: _googleLogin,
)
],
crossAxisAlignment: CrossAxisAlignment.stretch,
))
型
将内的文本(“继续使用Facebook”,“登录谷歌”)更改为较短的内容也可以解决这个问题。
测试(注意,我目前只是试图不出错,一旦我弄清楚了,Assert将被放进去)
testWidgets("Drawer",
(WidgetTester tester) async {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
BuildContext savedContext;
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
savedContext = context;
return Scaffold(
key: _scaffoldKey,
drawer: HomePageDrawer(),
body: Container(),
);
},
),
),
);
await tester.pump(); // no effect
_scaffoldKey.currentState.openDrawer();
await tester.pump();
});
型
1条答案
按热度按时间6rqinv9w1#
该错误指示Widget的大小超出了预期的范围。这个问题的解决方案是定义父部件的尺寸。使用SizedBox或Container应该有助于定义Widget的大小。