본문 바로가기
Flutter

[Flutter] add bottom margin for the last card in the listview : 카드 리스트 하단 마진 넣기

by hymndaniel 2022. 5. 23.

Motivation

카드 위젯을 리스트뷰로 리스팅했을때 하단에 마진을 추가하고 싶은 경우

 

ListView.builder(
      itemCount: list.length,
      itemBuilder: (context, index) {
        print(index);
        return Container(
          margin: EdgeInsets.only(
              left: 4,
              bottom: list.length - 1 == index ? 15 : 4,
              right: 4,
              top: 4),
          child: ListTile(
            tileColor: Colors.grey,
            title: Text(list[index].toString()),
          ),
        );
      })
 

 인덱스가 마지막인 경우의 마진을 설정함

 

Reference

https://stackoverflow.com/questions/69154200/how-to-add-bottom-margin-for-the-last-card-in-the-listview

 

How to add bottom margin for the last card in the listview?

How to add bottom margin for the last card in the listview? Currently there is no gap between bottom screen line and the last card in the listview. The listview is placed right in the body section.

stackoverflow.com

 


 

728x90