flutter-study
Flutter - ListView 사용하기
쥐수
2024. 7. 1. 20:34
728x90
ListView를 사용하면 가로 방향 혹은 세로 방향으로 여러 위젯들을 배치할 수 있다.
플러터에서 ListView는 GridView와 더불어서 많은 위젯들을 표시할 때 거의 필수적으로 사용되는 위젯이므로 반드시 이해해야 한다.
ListView를 생성하는 4가지 옵션
1. 일반적인 ListView를 명시적으로 호출하고 children를 전달하는 방법 => 적은 데이터에 사용시 용이하다.
2. ListView.builder 를 사용하여 동적으로 호출하는 방법 => 많은 양의 데이터 리스트에 용이하고, index도 사용 가능하다.
3. ListView.separated는 2번에 구분선 사용이 가능하다.
4. ListView.custom 사용
해당 코드는 전체 코드가 아닙니다!
body: ListView(
scrollDirection: Axis.horizontal, // 기본값은 vertical !
children: [
postContainer(title:"Title 1",colorData: Colors.blue),
postContainer(title:"Title 2",colorData: Colors.green),
postContainer(title:"Title 3",colorData: Colors.pink),
postContainer(title:"Title 4",colorData: Colors.purple),
postContainer(title:"Title 5",colorData: Colors.blueGrey)
]
),
해당 글의 전체 코드 : https://github.com/land-waters/flutter-study/blob/chap05/flutter_application_1/lib/main.dart
flutter-study/flutter_application_1/lib/main.dart at chap05 · land-waters/flutter-study
Contribute to land-waters/flutter-study development by creating an account on GitHub.
github.com
728x90