Overflow problems caused by using AlignedGridView, GridView, ListView and other components in Flutter

Overflow problems caused by using AlignedGridView, GridView, ListView and other components in Flutter

Problem recurrence

The error message is as follows

The following assertion was thrown during layout:
A RenderFlex overflowed by 189 pixels on the bottom.

The relevant error-causing widget was: 
  Column Column:file:///D:/DartProject/yqplaymusic/lib/components/CoverRow.dart:138:9
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#9b9fb OVERFLOWING
...  needs compositing
...  parentData: offset=Offset(0.0, 0.0) (can use size)
...  constraints: BoxConstraints(w=215.5, h=95.0)
...  size: Size(215.5, 95.0)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: start
...  textDirection: ltr
...  verticalDirection: down
====================================================================================================

Cause of the problem

Usually, this is because we are using components with uncertain width or height, such as Row, Column, and other components, and then using components with uncertain width and height in the sub-components, which will sometimes lead to the failure to calculate the height of the component correctly, which may occur briefly. Abnormal phenomenon, then normal againListView, GridView

Solution

In a child component, such asListView, use Row or replace and set the direction you want likeColumnListView

        ListView(
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
          physics: const NeverScrollableScrollPhysics(),
          children: [],
          )

It should be noted that the shrinkWrap attribute must be set to true so that ListView can automatically calculate the subcomponent size

Guess you like

Origin blog.csdn.net/qianxiamuxin/article/details/134790419