ListView 和 Expanded 在 flutter 中不起作用

ListView and Expanded not work in flutter

我需要帮助来解决这个问题。 expanded 呈现子项但不展开。

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\…\views\home_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 code

child code

滚动视图中不能有 ExpandedSignleChildScrollViewListView 等)

因为像这​​样你告诉扩展的 child 允许你占据整个垂直 space,而滚动视图可以允许无限垂直 space,所以简而言之,您是在告诉 Expanded 的 child 取无穷大。希望这可以澄清错误