1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SingleChildScrollViewにListViewのウィジェットを含ませる

Posted at

概要

掲題の件の実現に詰まり、下記のようなエラーと遭遇した。

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performResize():
Vertical viewport was given unbounded height.
Viewports expand in the scrolling direction to fill their container. In this case, a vertical
viewport was given an unlimited amount of vertical space in which to expand. This situation
typically happens when a scrollable widget is nested inside another scrollable widget.
If this widget is always nested in a scrollable widget there is no need to use a viewport because
there will always be enough vertical space for the children. In this case, consider using a Column
instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
the height of the viewport to the sum of the heights of its children.

と怒られる。。。

原因

SingleChildScrollViewとListView共に表示スペースを最大限まで取得しようとして、いたちごっこになっているせいなのかな?

解決策

下記のようにshrinkWrapphysicsを追加することで解決した。

        ListView.builder(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),

shrinkWrap

スクロールビューの範囲を、表示中のコンテンツによって決定するかどうかを指定するプロパティ。デフォルトはfalseであり、この場合はスクロールビューはスクロール軸において許容される最大サイズまで拡大される。

trueを明示することで、ListViewは必要最低限の表示スペースを取得する。

physics

スクロール方法を設定できるプロパティ。
NeverScrollableScrollPhysicsを設定するとスクロールができないようになる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?