Flutter

ListView & GridView

ListView, ListView.builder, GridView, ScrollController, item reuse, lazy loading

25 면접 질문·
Mid-Level
1

What is the main difference between ListView() and ListView.builder() in Flutter?

답변

ListView() creates all its children immediately, which can cause performance issues with long lists. ListView.builder() uses lazy loading and only creates widgets when they become visible on screen. For lists with many elements, ListView.builder() is recommended as it optimizes memory and performance by recycling off-screen widgets.

2

Which ListView.builder() parameter is required to specify the number of elements to display?

답변

The itemCount parameter tells ListView.builder() how many elements the list contains. Without this parameter, the list would be considered infinite and itemBuilder would be called indefinitely. Setting itemCount allows the framework to know when to stop building elements and display the scroll indicator correctly.

3

How to add a separator between each element of a ListView?

답변

ListView.separated() is specifically designed to display separators between elements. It takes a separatorBuilder in addition to itemBuilder, allowing you to define a custom widget (like a Divider) between each element. This approach is cleaner than manually adding separators in itemBuilder.

4

How to create a horizontal ListView in Flutter?

5

What is the role of the shrinkWrap parameter in a ListView?

+22 면접 질문

다음 면접을 위해 Flutter을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기