0
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?

Widgetの入れ子表示にforループを使っていたがListView.builder()にしたら楽すぎた

Posted at
  • 先ほどまでFlutterでWidgetの入れ子表示にはこんな感じのコードを使っていたのだが、いまいちComponentや他のViewとの相性が悪いという課題があった。
Row(
    children: [
      for(int i = 0; i < cover.length; i++) ... {
        TitleListComponent(cover: cover)
      }
    ],
),
  • そこでListViewモディファイアを用いる
 ListView.builder(
    itemCount: cover.length,
    itemBuilder: (context, index) {
      return TitleListComponent(cover: cover[index]);
    },
  ),
  • SwiftUIにおけるScrollViewVStackが一体化していて、とても使いやすい。
  • 従来のプログラミングによるインクリメントによる入れ子表示をする必要がなく、itemCountに最大値を入れたら勝手に0~最大値の範囲でコンポーネントを自動生成してくれる。
  • それでいてコードが短くて綺麗。

まだ知らないだけで、ListView特有の課題がありそうだけれども、しばらくはこれを使っていけばいいかな。

0
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
0
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?