Flutter drawer test errors with "A RenderFlex overflowed by 188 pixels on the right."
Asked Answered
V

1

7

I am writing some tests for my app. Currently I am stuck on testing the drawer. On emulators of various sizes it runs without a problem (from 240x432 to 1440x2960) but when I try to run a simple test the following error is thrown:

   ══╡ 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
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════

Within the code I have narrowed it down to some RaisedButtons. When the Row within is below a certain length, the error doesn't show.

When I comment out the following code, ALL tests run without an issue.

          Padding(
          padding: EdgeInsets.symmetric(vertical: 32, horizontal: 16),
          child: Column(
            children: [
              FacebookSignInButton(
                onPressed: _fbLogin,
              ),
              GoogleSignInButton(
                onPressed: _googleLogin,
              )
            ],
            crossAxisAlignment: CrossAxisAlignment.stretch,
          ))

Changing the text within ("Continue with Facebook", "Sign in with Google") to something shorter also fixes this.

The test (note I'm currently just trying to not error, asserts will be put in once I get this figured out)

   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();
    });
Valais answered 18/8, 2019 at 10:4 Comment(2)
It appears that six months after you posted this, I am stuck with the same issue. Did you manage to resolve it?Admit
@Admit I ended up doing something else. However, if I tried this now I'd probably wrap it in an Expanded widget.Valais
R
0

The error indicates that the size of the Widget exceeds the bounds expected. A solution for this issue is to define the dimensions of the parent widget. Using either a SizedBox or Container should help define the size of the Widget.

Rivera answered 4/8, 2023 at 4:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.