๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[Flutter] ๊ธฐ๋ณธ ๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•˜๋Š” Scaffold ์œ„์ ฏ ๋ณธ๋ฌธ

๐Ÿ“ฑFlutter/Flutter Framework

[Flutter] ๊ธฐ๋ณธ ๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•˜๋Š” Scaffold ์œ„์ ฏ

๋ฃจ๋ฆฌ์•ผใ…‘ 2025. 1. 20. 23:16
๋ฐ˜์‘ํ˜•

ํ”Œ๋Ÿฌํ„ฐ์—์„œ Scaffold ์œ„์ ฏ์€ ์•ฑ์˜ ํ™”๋ฉด ๋ ˆ์ด์•„์›ƒ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ธฐ๋ณธ์ ์ธ ํ‹€์„ ์ œ๊ณตํ•œ๋‹ค.
๋ชจ๋“  ํ”Œ๋Ÿฌํ„ฐ ์•ฑ์˜ ํ™”๋ฉด์€ ๋ณดํ†ต Scaffold ์œ„์ ฏ์œผ๋กœ ์‹œ์ž‘๋œ๋‹ค.

Scaffold๋Š” AppBar, body, FloatingActionButton ๋“ฑ์„ ํฌํ•จํ•œ
ํ”Œ๋Ÿฌํ„ฐ์˜ Material Design ๊ฐ€์ด๋“œ๋ผ์ธ์— ๋”ฐ๋ผ ๊ธฐ๋ณธ UI ๊ตฌ์กฐ๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

Scaffold๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, ๊ธฐ๋ณธ ๋ ˆ์ด์•„์›ƒ์„ ๋น ๋ฅด๊ฒŒ ์„ค๊ณ„ํ•  ์ˆ˜ ์žˆ๊ณ , Material Design ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ๊ฐ€ ๊ธฐ๋ณธ ์Šคํƒ€์ผ์— ์ ์šฉ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊น”๋”ํ•˜๊ฒŒ ์ ์šฉ๋œ๋‹ค. ๊ทธ๋ฆฌ๊ณ , body ์˜์—ญ์— ์›ํ•˜๋Š” ๋ชจ๋“  ์œ„์ ฏ์„ ๋ฐฐ์น˜ํ•˜์—ฌ ๋ณต์žกํ•œ ๋ ˆ์ด์•„์›ƒ ์„ค๊ณ„๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

Scaffold ์ฃผ์š” ์†์„ฑ

1. appBar

ํ™”๋ฉด ์ƒ๋‹จ์— ๋‚˜ํƒ€๋‚˜๋Š” AppBar ์˜์—ญ.
์ œ๋ชฉ, ๋ฒ„ํŠผ, ๋ฉ”๋‰ด ๋“ฑ์„ ํฌํ•จํ•  ์ˆ˜ ์žˆ๋‹ค.

Scaffold(
  appBar: AppBar(
    title: Text('์•ฑ๋ฐ” ์ œ๋ชฉ'),
  ),
)

 

2. body

ํ™”๋ฉด์˜ ์ฃผ์š” ์ฝ˜ํ…์ธ ๋ฅผ ๋ฐฐ์น˜ํ•˜๋Š” ์˜์—ญ์ด๋‹ค.
๋ณธ๋ฌธ์— ํ‘œ์‹œํ•  UI์œ„์ ฏ์„ ์—ฌ๊ธฐ์— ์ถ”๊ฐ€ํ•œ๋‹ค.

Scaffold(
  body: Center(
    child: Text('Scaffold ๋ณธ๋ฌธ ์ฝ˜ํ…์ธ '),
  ),
)

 

3. floatingActionButton

ํ™”๋ฉด ํ•˜๋‹จ ์˜ค๋ฅธ์ชฝ์— ๋‚˜ํƒ€๋‚˜๋Š” ๋ฒ„ํŠผ์ด๋‹ค.
์ฃผ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์ž์ฃผ ๋ˆ„๋ฅด๊ฒŒ ๋  ์ฃผ์š” ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฒ„ํŠผ์ด๋‹ค.

Scaffold(
  floatingActionButton: FloatingActionButton(
    onPressed: () {
      print('FAB ํด๋ฆญ');
    },
    child: Icon(Icons.add),
  ),
)

 

4. drawer

ํ™”๋ฉด ์™ผ์ชฝ์— ๋‚˜ํƒ€๋‚˜๋Š” Drawer.
๋ฉ”๋‰ด๋ฅผ ์—ด ์ˆ˜ ์žˆ๋Š” ์‚ฌ์ด๋“œ๋ฐ”.

Scaffold(
  drawer: Drawer(
    child: ListView(
      children: [
        DrawerHeader(
          child: Text('๋“œ๋กœ์–ด ํ—ค๋”'),
        ),
        ListTile(
          title: Text('ํ•ญ๋ชฉ 1'),
          onTap: () {},
        ),
      ],
    ),
  ),
)

 

5. bottomNavigationBar

ํ™”๋ฉด ํ•˜๋‹จ์— ๊ณ ์ •๋œ ํ•˜๋‹จ ๋‚ด๋น„๊ฒŒ์ด์…˜ ๋ฐ”.
์—ฌ๋Ÿฌ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ํƒญ์ด๋‚˜ ๋ฒ„ํŠผ์„ ํฌํ•จํ•œ๋‹ค.

Scaffold(
  bottomNavigationBar: BottomNavigationBar(
    items: [
      BottomNavigationBarItem(icon: Icon(Icons.home), label: 'ํ™ˆ'),
      BottomNavigationBarItem(icon: Icon(Icons.search), label: '๊ฒ€์ƒ‰'),
    ],
  ),
)

 

์˜ˆ์ œ ์ฝ”๋“œ

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Scaffold ์˜ˆ์ œ'),
        ),
        body: Center(
          child: Text('Scaffold์˜ ๋ณธ๋ฌธ์ž…๋‹ˆ๋‹ค.'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            print('ํ”Œ๋กœํŒ… ๋ฒ„ํŠผ ํด๋ฆญ!');
          },
          child: Icon(Icons.add),
        ),
        drawer: Drawer(
          child: ListView(
            children: [
              DrawerHeader(
                child: Text('๋“œ๋กœ์–ด ํ—ค๋”'),
              ),
              ListTile(
                title: Text('ํ•ญ๋ชฉ 1'),
                onTap: () {},
              ),
            ],
          ),
        ),
        bottomNavigationBar: BottomNavigationBar(
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: 'ํ™ˆ'),
            BottomNavigationBarItem(icon: Icon(Icons.search), label: '๊ฒ€์ƒ‰'),
          ],
        ),
        backgroundColor: Colors.grey[200],
      ),
    );
  }
}
๋ฐ˜์‘ํ˜•