5
1

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.

[Flutter] ListView.separated() で、一番最後にDivider()を表示する

Posted at

ListView.separated() はアイテム間に区切りを表示できて便利だが、一番最後にも区切りを表示したい時がある。

やり方

itemCountを項目数+1しておき、itemBuilderindex==<項目数>となったとき、区切りを返す。

ListView.separated(
  itemBuilder: (BuildContext context, int index) {
    if (index == items.length) {
      return const Divider(
        height: 1,
      );
    }
    return ListTile(
      title: items[index].title,
    );
  },
  separatorBuilder: (BuildContext context, int index) {
    return const Divider(
      height: 1,
    );
  },
  itemCount: items.length + 1,
);

参考

Adding top and bottom separators with ListView.separated | Code With Andrea

5
1
1

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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?