새소식

반응형
App/Flutter

[Flutter] listview 와 listview.builder 차이점

  • -
반응형

2023-12-07


사진: Unsplash 의 Masood Aslami


1. listview 

 

명시적으로 지정된 만큼 스크롤 가능한 선형 위젯 배열을 만든다. 이 생성자는 하위 수가 적은 목록 보기에 적합핟. 목록을 구성하려면 실제로 표시되는 하위 항목만이 아니라 목록 보기에 표시될 수 있는 모든 하위 항목에 대해 작업을 수행해야 하기 때문이다. 즉 10000개의 항목들을 리스트로 만들어야 한다면 10000개를 모두 리스트에 그려야 하기 때문에 비효율적일 수 있다.

 

https://api.flutter.dev/flutter/widgets/ListView-class.html

 

ListView class - widgets library - Dart API

A scrollable list of widgets arranged linearly. ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. In the cross axis, the children are required to fill the ListView. If non-null, the ite

api.flutter.dev


2. listview.builder

 

ListView.builder는 요청 시 생성되는 스크롤 가능한 선형 위젯 배열을 생성한다. 이 생성자는 실제로 표시되는 하위 항목에 대해서만(현재 화면에 보여야 하는 리스트) 빌더가 호출되므로 하위 항목 수가 많거나 무한한 목록 보기에 적합하다. 즉 10000개의 항목 중 현재 화면에 15개 정도의 항목들만 리스트에 보이고 있다면 실제 위젯으로 생성되는 항목도 15개라는 뜻이다.

 

https://docs.flutter.dev/cookbook/lists/long-lists

 

Work with long lists

Use ListView.builder to implement a long or infinite list.

docs.flutter.dev


3. 차이점 요약

 

기본적으로 listview.builder 생성자는 지연된(Lazy) 목록을 생성하기 때문에 사용자가 목록을 아래로 스크롤하면 Flutter는 '요청 시' 위젯을 빌드한다. 기본 listview 생성자는 전체 목록을 한 번에 작성한다.


4. 참고

https://stackoverflow.com/questions/56272328/what-is-the-difference-between-listview-and-listview-builder-and-can-we-use-list

 

What is the difference between ListView and ListView.builder and can we use Listview.builder to create and validate and submit f

What is the difference between Listview.builder and Listview? Can we use ListView.builder to submit forms? I am using the Listview.builder now to create forms.

stackoverflow.com


메인 이미지 출처 : 사진: UnsplashMasood Aslami

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.