๐ŸŒžโญ๐ŸŒœ๐ŸŒˆ
๋‰ด์ฐจํŠธ
๐ŸŒžโญ๐ŸŒœ๐ŸŒˆ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ
    • Flutter
    • Android
    • Algorithm
      • Python
    • Test
    • Python
    • ์ƒ์‚ฐ์„ฑ
    • ๊ฒฝ์ œ
    • ์˜์–ด
    • ์ƒํ™œ ํŒ

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ํƒœ๊ทธ
  • ๋ฐฉ๋ช…๋ก

๊ณต์ง€์‚ฌํ•ญ

ํƒœ๊ทธ

  • Flutter ํ˜„์žฌ
  • Android
  • ๋„ค์ด๋น„ ์”ฐ ์ผ์ฐ ์ž๋Š” ๋ฒ•
  • Flutter ๊ณผ๊ฑฐ
  • ์ฐฝ๋ถ€์บ 
  • flutter webview
  • ์ฐฝ์—…๋ถ€ํŠธ์บ ํ”„
  • Flutter Web
  • flutter
  • cruscal
  • Flutter ๊ธฐ์ดˆ ์‹œ๋ฆฌ์ฆˆ
  • Flutter ๋ฏธ๋ž˜
  • ํŒŒ์ด์ฌ
  • Flutter pattern
  • enum
  • PYTHON
  • null safety
  • Python ๋‚ด์žฅ ํ•จ์ˆ˜
  • bloc
  • getx
  • ํŠน์ง•
  • ๋ผ์ดํ”„ํ•ดํ‚น์Šค์ฟจ
  • ๊ฐ“์ƒ
  • Image.memory
  • Firebase
  • flutter 2.0
  • Flutter ์˜ ์—ญ์‚ฌ
  • ์ผ์ฐ ์ž๋Š” ๋ฒ•
  • AssetThumb
  • python ๋‚ด์žฅํ•จ์ˆ˜

์ตœ๊ทผ ๋Œ“๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
๐ŸŒžโญ๐ŸŒœ๐ŸŒˆ

๋‰ด์ฐจํŠธ

Flutter Widget #1 : ListView ์ดํ•ด์™€ ์‚ฌ์šฉ๋ฐฉ๋ฒ•
Flutter

Flutter Widget #1 : ListView ์ดํ•ด์™€ ์‚ฌ์šฉ๋ฐฉ๋ฒ•

2022. 3. 5. 23:33

Flutter์—์„œ ListView ์‚ฌ์šฉ์€ ๋งค์šฐ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. 3๊ฐœ์˜ ํ•ต์‹ฌ ListView ๊ตฌํ˜„ ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๊ณ  ๊ฐ๊ฐ์˜ ์˜ˆ์ œ๋ฅผ ํ™•์ธํ•˜๋ฉด์„œ ListView๋ฅผ ์ตํ˜€๋ด…์‹œ๋‹ค. 

 

์ด๋ฒˆ ๊ธ€์—์„œ ์•Œ์•„๋ณผ ๋‚ด์šฉ

  • ListView๋ž€?
  • ListView()
  • ListView.builder()
  • ListView.separated()

 

ListView๋ž€?

ListView๋Š” Flutter์—์„œ ์Šคํฌ๋กค์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์œ„์ ฏ์ž…๋‹ˆ๋‹ค. ๊ตฌํ˜„ํ•˜๊ธฐ๋„ ์‰ฝ๊ณ  ์œ ์—ฐํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. vertical, horizontal ์Šคํฌ๋กค ๋ฐฉํ–ฅ์„ ๋ฐ”๊ฟ€ ์ˆ˜๋„ ์žˆ์œผ๋ฉฐ, ์•„๋ž˜์—์„œ๋„ ๋ณด์‹œ๊ฒ ์ง€๋งŒ ListView.sperated() ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ ์•„์ดํ…œ ์‚ฌ์ด์— ๋‹ค๋ฅธ ์š”์†Œ๋ฅผ ์ง‘์–ด๋„ฃ์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ ListView ๊ตฌํ˜„์˜ ๋Œ€ํ‘œ์  3๊ฐ€์ง€๋ฅผ ์•Œ์•„๋ด…์‹œ๋‹ค.

 

ListView()

ListView๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ children:[] ์„ ํ†ตํ•ด ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Column, Row์™€ ๊ฐ™์ด children:[] ์„ ์„ค์ •ํ•˜๋ฉด ์Šคํฌ๋กค ๊ฐ€๋Šฅํ•œ ListView๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์ข€ ๋” ์ž์„ธํžˆ ํŒŒ์•…ํ•ด๋ณด์„ธ์š”.

 

ListView(
  padding: const EdgeInsets.all(8),
  children: <Widget>[
    Container(
      height: 50,
      color: Colors.amber[600],
      child: const Center(child: Text('Entry A')),
    ),
    Container(
      height: 50,
      color: Colors.amber[500],
      child: const Center(child: Text('Entry B')),
    ),
    Container(
      height: 50,
      color: Colors.amber[100],
      child: const Center(child: Text('Entry C')),
    ),
  ],
)

 

ListView.builder()

๋‹ค์Œ์€ ListView.builder()๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. itemCount ์™€ itemBuilder๋ฅผ ๊ตฌํ˜„ํ•˜์‹œ๋ฉด ๋˜๋Š”๋ฐ์š”. itemCount๋งŒํผ itemBuilder๋ฅผ ์‹คํ–‰์‹œ์ผœ widget์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋˜๋ฉด ๋ฐ˜ํ™˜ํ•œ widget๋“ค์ด ์Œ“์—ฌ ListView๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋Š” ๊ฒƒ ์ž…๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.

 

final List<String> entries = <String>['A', 'B', 'C'];
final List<int> colorCodes = <int>[600, 500, 100];

ListView.builder(
  padding: const EdgeInsets.all(8),
  itemCount: entries.length,
  itemBuilder: (BuildContext context, int index) {
    return Container(
      height: 50,
      color: Colors.amber[colorCodes[index]],
      child: Center(child: Text('Entry ${entries[index]}')),
    );
  }
);

 

ListView.separated()

ListView.sperated()๋Š” ๊ฐ ์š”์†Œ ์‚ฌ์ด์— ๋‹ค๋ฅธ ์š”์†Œ๋ฅผ ๋„ฃ๊ฒŒ ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์ธ๋ฐ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด ListView ๊ฐ ์š”์†Œ ์‚ฌ์ด์— Divider๋ฅผ ๋„ฃ๊ณ  ์‹ถ์„๋•Œ๋Š” ์ด ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ตฌํ˜„๋ฐฉ๋ฒ•์€ ListView.builder()์—์„œ seperatedBuilder๋งŒ ์ถ”๊ฐ€์ ์œผ๋กœ ๊ตฌํ˜„ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ์ฝ”๋“œ์™€ ์‚ฌ์ง„์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”.

 

final List<String> entries = <String>['A', 'B', 'C'];
final List<int> colorCodes = <int>[600, 500, 100];

ListView.separated(
  padding: const EdgeInsets.all(8),
  itemCount: entries.length,
  itemBuilder: (BuildContext context, int index) {
    return Container(
      height: 50,
      color: Colors.amber[colorCodes[index]],
      child: Center(child: Text('Entry ${entries[index]}')),
    );
  },
  separatorBuilder: (BuildContext context, int index) => const Divider(),
);

 

์ฐธ๊ณ ์ž๋ฃŒ

  • ListView - Flutter Api Document

'Flutter' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Flutter / Flutter GetX์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž  (0) 2022.03.04
Flutter ๊ธฐ์ดˆ - 2ํƒ„ : ํ™”๋ฉด์— ๊ทธ๋ ค์ง€๋Š” ๋ชจ๋“  ๊ฒƒ์€ ์œ„์ ฏ์ด๋‹ค  (0) 2022.02.12
Flutter BLoC ๊ฟ€ํŒ - 1ํƒ„ : BlocProvider ๋ฐฑ๋ฐฐ ์‚ฌ์šฉํ•˜๊ธฐ  (0) 2022.01.21
Flutter ๊ธฐ์ดˆ - 1ํƒ„ : Flutter ์˜ ๊ณผ๊ฑฐ, ํ˜„์žฌ, ๋ฏธ๋ž˜  (0) 2021.12.17
Flutter Web 1ํƒ„ : ๊ตฌ๊ธ€ ์ฝ”๋“œ๋žฉ ๊ตฌํ˜„  (0) 2021.07.20
    'Flutter' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • Flutter / Flutter GetX์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž
    • Flutter ๊ธฐ์ดˆ - 2ํƒ„ : ํ™”๋ฉด์— ๊ทธ๋ ค์ง€๋Š” ๋ชจ๋“  ๊ฒƒ์€ ์œ„์ ฏ์ด๋‹ค
    • Flutter BLoC ๊ฟ€ํŒ - 1ํƒ„ : BlocProvider ๋ฐฑ๋ฐฐ ์‚ฌ์šฉํ•˜๊ธฐ
    • Flutter ๊ธฐ์ดˆ - 1ํƒ„ : Flutter ์˜ ๊ณผ๊ฑฐ, ํ˜„์žฌ, ๋ฏธ๋ž˜
    ๐ŸŒžโญ๐ŸŒœ๐ŸŒˆ
    ๐ŸŒžโญ๐ŸŒœ๐ŸŒˆ

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”