我需要帮助来解决这个问题。展开的渲染子元素,但不展开。
return Scaffold(
body: ListView(
children: [
_HomeBody(child: child,)
],
)
);
_HomeBody
return Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height
child: Column(
children: [
AppBarMenu(),
Expanded(child: child), // A RenderFlex overflowed by 1246 pixels on the bottom.
Footer()
],
),
);
错误输出
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 1246 pixels on the bottom.
The relevant error-causing widget was:
Column
lib…viewshome_view.dart:19
The overflowing RenderFlex has an orientation of Axis.vertical.
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#90f9f OVERFLOWING:
needs compositing
creator: Column ← ConstrainedBox ← Container ← HomeView ← Builder ←
RepaintBoundary-[GlobalKey#97a2c] ← IgnorePointer ← AnimatedBuilder ← FractionalTranslation ←
SlideTransition ← AnimatedBuilder ← RepaintBoundary ← ⋯
parentData: <none> (can use size)
constraints: BoxConstraints(w=966.0, h=840.0)
size: Size(966.0, 840.0)
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: start
textDirection: ltr
verticalDirection: down
HomeLayout代码
子代码
你不能让Expanded
在滚动视图内(SignleChildScrollView
,ListView
等)
因为像这样,你是在告诉扩展的子视图占用你允许的整个垂直空间,而滚动视图可以允许无限的垂直空间,所以简而言之,你是在告诉Expanded
的子视图占用无穷大的大小。希望这能澄清错误