Design-loving front-end engineer
Ryong
Design-loving front-end engineer
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
    • Framework
    • React
      • Concept
      • Library
      • Hook
      • Component
      • Test
    • NodeJS
    • Android
      • Concept
      • Code
      • Sunflower
      • Etc
    • Flutter
      • Concept
      • Package
    • Web
    • Web
    • CSS
    • Language
    • JavaScript
    • TypeScript
    • Kotlin
    • Dart
    • Algorithm
    • Data Structure
    • Programmers
    • Management
    • Git
    • Editor
    • VSCode
    • Knowledge
    • Voice
Design-loving front-end engineer

Ryong

[ Flutter ] ๋ฆฌ์ŠคํŠธ
Flutter/Concept

[ Flutter ] ๋ฆฌ์ŠคํŠธ

2022. 2. 27. 17:52

SingleChildScrollView

๐Ÿ’ฌ  SingleChildScrollView๋Š” ํ•˜๋‚˜์˜ ์ž์‹ ์œ„์ ฏ๋งŒ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ’ฌ  Column์„ ์ž์‹ ์œ„์ ฏ์œผ๋กœ ์„ค์ •ํ•˜๋ฉด ํ‘œ์‹œํ•  ์œ„์ ฏ์˜ ํฌ๊ธฐ๋งŒํผ ๊ฐ€๋กœ ๊ธธ์ด๋ฅผ ๊ฐ€์ง€๋ฉฐ, ListBody๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์Šคํฌ๋กค ๊ฐ€๋Šฅ ์˜์—ญ์ด ๊ฐ€๋กœ๋กœ ๊ฝ‰ ์ฐจ๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ์ž๊ฐ€ ์Šคํฌ๋กคํ•˜๊ธฐ ๋” ์‰ฌ์›Œ์ง„๋‹ค.

์˜ˆ์ œ

๋”๋ณด๊ธฐ
final items = List.generate(100, (i) => i).toList();  // 0๋ถ€ํ„ฐ 99๊นŒ์ง€์˜ ๊ฐ’์„ ๊ฐ–๋Š” ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ

SingleChildScrollView(
  child: ListBody(
    children: items.map((i) => Text('$i')).toList(),
  ),
),

 

ListView, ListTile

๐Ÿ’ฌ  SingleChildScrollView์™€ ListBody์˜ ์กฐํ•ฉ๊ณผ ๋™์ผํ•œ ํšจ๊ณผ๋ฅผ ๋‚ด์ง€๋งŒ, ์ข€ ๋” ๋ฆฌ์ŠคํŠธ ํ‘œํ˜„์— ์ตœ์ ํ™”๋œ ์œ„์ ฏ์ด๋‹ค.

๐Ÿ’ฌ  ListTile ์œ„์ ฏ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ ์•„์ดํ…œ์„ ์‰ฝ๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ’ฌ  ListView์˜ children ํ”„๋กœํผํ‹ฐ์— ๋‹ค์ˆ˜์˜ ์œ„์ ฏ์„ ๋ฐฐ์น˜ํ•˜๋ฉด ์ •์ ์ธ ๋ฆฌ์ŠคํŠธ๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ’ฌ  ListTile ์œ„์ ฏ

    โ—ฝ  ์•„์ด์ฝ˜์ด๋‚˜ ๊ธ€์ž๋ฅผ leading (์™ผ์ชฝ), title (์ค‘์•™), trailing (์˜ค๋ฅธ์ชฝ)์— ์œ„์น˜์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

    โ—ฝ  onTap ํ”„๋กœํผํ‹ฐ์—๋Š” ๋ฆฌ์ŠคํŠธ์˜ ํ•ญ๋ชฉ์„ ํ„ฐ์น˜ํ–ˆ์„ ๋•Œ ์‹คํ–‰ํ•˜๋Š” ๋™์ž‘์„ ์ •์˜ํ•œ๋‹ค.

์˜ˆ์ œ

๋”๋ณด๊ธฐ
ListView(
  scrollDirection: Axis.vertical,
  children: <Widget>[
    ListTile(
      leading: Icon(Icons.home),
      title: Text('Home'),
      trailing: Icon(Icons.navigate_next),
      onTap: () { },
    ),
    ListTile(
      leading: Icon(Icons.event),
      title: Text('Event'),
      trailing: Icon(Icons.navigate_next),
      onTap: () { },
    ),
    ListTile(
      leading: Icon(Icons.camera),
      title: Text('Camera'),
      trailing: Icon(Icons.navigate_next),
      onTap: () { },
    ),
  ],
),

 

List.generate

List.generate(
  itemList.length,
  (index) => _buildItem(itemList[index]),
),

โ—ฝ  length ๊ธธ์ด๋งŒํผ 0๋ถ€ํ„ฐ index - 1๊นŒ์ง€ ๋ฒ”์œ„์˜ ๊ฐ ์ธ๋ฑ์Šค๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ํ˜ธ์ถœํ•˜์—ฌ ๋งŒ๋“  ๊ฐ’์œผ๋กœ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ƒ์„ฑ

 

ListView.separated

ListView.separated(
  separatorBuilder: (context, index) => Divider(
    height: 0,
    indent: 16,     // ๊ตฌ๋ถ„์„  ์•ž๋ถ€๋ถ„ margin
    endIndent: 16,  // ๊ตฌ๋ถ„์„  ๋’ท๋ถ€๋ถ„ margin
    color: Colors.grey,
  ),
  itemBuilder: (context, index) {
    return Item(
      item: itemList[index]
    );
  },
  itemCount: itemList.length,
),

โ—ฝ  ListView ์•„์ดํ…œ๋“ค ์‚ฌ์ด์— ๊ตฌ๋ถ„์„ ์„ ์ฃผ๋Š” ์œ„์ ฏ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

CheckboxListTile

๐Ÿ’ฌ  ์ฒดํฌ๋ฐ•์Šค๊ฐ€ ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

CheckboxListTile(
  title: const Text('Animate Slowly'),
  secondary: const Icon(Icons.hourglass_empty),
  value: _check,
  onChanged: (value) {
    setState(() {
      _check = value;
    }
  },
),

 

SwitchListTile

๐Ÿ’ฌ  ํ† ๊ธ€์ด ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

SwitchListTile(
  title: const Text('Light'),
  secondary: const Icon(Icons.lightbulb_outline),
  value: _lights,
  onChanged: (value) {
    setState(() {
      _lights = value;
    }
  },
),

 

ExpansionPanelList

๐Ÿ’ฌ  ์ ‘์—ˆ๋‹ค ํŽผ ์ˆ˜ ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

ExpansionPanelList(
  expansionCallback: (int index, bool isExpanded) {
    action(index, isExpanded);
  },
  children: _data.map<ExpansionPanel>((Item item) {
    return ExpansionPanel(
      headerBuilder: (BuildContext context, bool isExpanded) {
        return _header(item);
      },
      body: _body(item),
      isExpanded: item.isExpanded,
    );
  }).toList(),
);

 

์ €์ž‘์žํ‘œ์‹œ (์ƒˆ์ฐฝ์—ด๋ฆผ)

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

[ Flutter ] ์ŠคํŠธ๋ฆผ  (0) 2022.02.27
[ Flutter ] ํ™”๋ฉด ํ‘œ์‹œ  (0) 2022.02.27
[ Flutter ] ํ…์ŠคํŠธ  (0) 2022.02.27
[ Flutter ] ํ”Œ๋žซํผ ๋Œ€์‘  (0) 2022.02.24
[ Flutter ] ์ด๋ฏธ์ง€  (0) 2022.02.22
    'Flutter/Concept' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [ Flutter ] ์ŠคํŠธ๋ฆผ
    • [ Flutter ] ํ™”๋ฉด ํ‘œ์‹œ
    • [ Flutter ] ํ…์ŠคํŠธ
    • [ Flutter ] ํ”Œ๋žซํผ ๋Œ€์‘
    Design-loving front-end engineer
    Design-loving front-end engineer
    ๋””์ž์ธ์— ๊ด€์‹ฌ์ด ๋งŽ์€ ๋ชจ๋ฐ”์ผ ์•ฑ ์—”์ง€๋‹ˆ์–ด Ryong์ž…๋‹ˆ๋‹ค.

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