简体   繁体   English

ListView 和 Expanded 在颤动中不起作用

[英]ListView and Expanded not work in flutter

I need help to solve this problem.我需要帮助来解决这个问题。 The expanded renders the child but does not expand.展开后会渲染孩子,但不会展开。

return Scaffold(
  body: ListView(
    children:  [

      _HomeBody(child: child,)

    ],
  )
);

_HomeBody _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()
    ],
  ),
);

Error Output错误输出

══╡ 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子代码

You can't have Expanded inside of a scrolling view ( SignleChildScrollView , ListView , etc..)您不能在滚动视图( SignleChildScrollViewListView等)内Expanded

cause like this you are telling the child of the expanded to take of the whole vertical space allowed to you, and the scroll view can allow infinite vertical space, so in a nutshell, you are telling the child of the Expanded take the size of infinity.像这样的原因,您是在告诉展开后的子代占用您允许的整个垂直空间,而滚动视图可以允许无限的垂直空间,所以简而言之,您是在告诉Expanded后的子代占用无穷大的大小. hope this clarifies the error希望这可以澄清错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM