Flutter で AlignedGridView、GridView、ListView、その他のコンポーネントを使用することによって発生するオーバーフローの問題

Flutter で AlignedGridView、GridView、ListView、その他のコンポーネントを使用することによって発生するオーバーフローの問題

問題の再発

エラーメッセージは次のとおりです

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
====================================================================================================

問題の原因

通常、これは、RowColumn およびその他のコンポーネントを使用し、サブコンポーネントで幅と高さが不確かなコンポーネントを使用すると、コンポーネントの高さが正しく計算されない場合があり、一時的に発生する可能性があります。 . 異常現象、その後正常に戻るListViewGridView

解決

ListView などの子コンポーネントでは、Row または 交換して希望の方向を設定しますColumnListView

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

がサブコンポーネントを自動的に計算できるように、shrinkWrap 属性を true に設定する必要があることに注意してください。サイズListView

おすすめ

転載: blog.csdn.net/qianxiamuxin/article/details/134790419