2026년 상식닷컴 선정 식당 & 카페 리스트
최근에 오픈한 호텔을 찾는다면 살펴보세요

ListView.custom

작성: sangseek | 게시 날짜: 2026/05/26 | 조회수: 26
[ 편집불가 ]

ListView.custom은 Flutter의 ListView 클래스가 제공하는 생성자 중 하나로, 자식 위젯을 어떻게 제공할지(SliverChildDelegate)를 직접 지정할 수 있게 해 주는 생성자입니다. 즉, children 리스트를 직접 넘기거나 builder를 간단히 쓰는 대신, SliverChildDelegate(예: SliverChildBuilderDelegate, SliverChildListDelegate)를 사용해 자식 생성 방식과 캐싱·유지 정책 등을 세밀하게 제어할 수 있습니다. 주요 특징 - childrenDelegate라는 한 가지 핵심 매개변수를 받아서 자식 생성 전략을 위임한다. - SliverChildBuilderDelegate를 쓰면 인덱스 기반으로 필요할 때마다 자식을 지연 생성(lazy building)할 수 있다. - SliverChildListDelegate를 쓰면 고정된 자식 리스트를 그대로 사용한다. - SliverChildDelegate의 옵션(addAutomaticKeepAlives, addRepaintBoundaries, addSemanticIndexes 등)을 통해 KeepAlive, repaint boundary, semantic index 처리 방식을 세부적으로 제어할 수 있다. ListView의 다른 생성자와의 차이 - ListView(children: [...])는 내부적으로 SliverChildListDelegate를 사용한다(정적 리스트). - ListView.builder(...)는 SliverChildBuilderDelegate를 사용한다(인덱스 기반 빌더, 일반적 지연 빌드). - ListView.custom(childrenDelegate: ...)는 위 두 방식보다 더 유연하게 직접 SliverChildDelegate를 넘겨 원하는 동작을 구현할 수 있게 한다. 사용 예 (간단) - SliverChildBuilderDelegate 사용: ListView.custom( childrenDelegate: SliverChildBuilderDelegate( (context, index) => MyItem(index), childCount: 100, addAutomaticKeepAlives: true, ), ); - SliverChildListDelegate 사용: ListView.custom( childrenDelegate: SliverChildListDelegate([ Text('A'), Text('B'), ]), ); 언제 사용하나 - 기본 제공되는 ListView.children / builder / separated로는 제어하기 어려운 특별한 자식 생성, 캐시, keep-alive, semantic 인덱스 처리 등이 필요할 때. - 여러 다른 소스에서 동적으로 자식을 병합하거나, 커스텀 SliverChildDelegate를 만들어 고유한 빌드/메모리 전략을 적용하려 할 때. 성능 주의 - SliverChildBuilderDelegate를 쓰면 큰 리스트에서 효율적으로 동작하지만, SliverChildListDelegate로 아주 큰 리스트를 바로 넣으면 메모리/성능 문제가 생길 수 있다. - SliverChildDelegate의 옵션을 적절히 설정해 불필요한 rebuild나 과도한 메모리 사용을 줄이세요.
내용이 부정확하다면 싫어요를 누르세요.