MaterialApp
Material Design์ ๊ธฐ๋ฐ์ผ๋ก ์ค๊ณ๋, ํ๋ฌํฐ์์ ์ ๊ณตํ๋ ์ต์์ ์์ ฏ
๊ธฐ๋ณธ ์ค์
โข
์ ๋ชฉ:ย ์ฑ์ ์ ๋ชฉ์ ์ค์ ํฉ๋๋ค.
โข
ํ
๋ง:ย ์ฑ์ ์ ์ฒด์ ์ธ ๋์์ธ์ ๊ด๋ฆฌํฉ๋๋ค.
โข
ํ์ด์ง ์ด๋ ๊ฒฝ๋ก:ย ์ฑ์ ํ์ด์ง ์ด๋ ๊ฒฝ๋ก๋ฅผ ์ค์ ํฉ๋๋ค.
โข
๋๋ฒ๊ทธ ๋ชจ๋:ย ๋๋ฒ๊ทธ ๋ชจ๋๋ฅผ ํ์ฑํํฉ๋๋ค.
Material Design
: ๊ตฌ๊ธ์์ ์ ๊ณตํ๋ ๋์์ธ ๊ฐ์ด๋๋ผ์ธ์ผ๋ก, ์ฑ์ ์ฌ์ฉ์ ๊ฒฝํ์ ํฅ์์ํค๊ธฐ ์ํ ์ผ๋ จ์ ์ง์นจ์ ์ ๊ณตํฉ๋๋ค.
MaterialApp ์ ์ฃผ์ ์์ ฏ
์์ ฏ | ์ค๋ช
|
Scaffold | ์ฑ์ ๊ธฐ๋ณธ ๊ตฌ์กฐ๋ฅผ ์ ๊ณตํ๋ ์์ ฏ |
AppBar | ์ฑ์ ์๋จ์ ํ์๋๋ ์์ ฏ |
Body | ์ฑ์ ์ฃผ์ ๋ด์ฉ์ ํฌํจํ๋ ์์ ฏ |
BottomNavigationBar | ์ฑ์ ํ๋จ์ ํ์๋๋ ์์ ฏ |
FloatingActionButton | ํ๋ฉด์ ๋ ๋ค๋๋ ๋ฒํผ |
TabBar | ํญ์ ์ ๊ณตํ๋ ์์ ฏ |
MaterialApp
์ฑ์ ๊ธฐ๋ณธ ์ค์ ๊ณผ ํ
๋ง(๋์์ธ)๋ฅผ ๊ด๋ฆฌํ๋ ์ต์์ ์์ ฏ
์์ฑ
์์ฑ | ์ค๋ช
|
title | ์ฑ์ ์ ๋ชฉ์ ์ค์ ํฉ๋๋ค. |
theme | ์ฑ์ ํ
๋ง๋ฅผ ์ค์ ํฉ๋๋ค. |
routes | ์ฑ์ ํ์ด์ง ์ด๋ ๊ฒฝ๋ก๋ฅผ ์ค์ ํฉ๋๋ค. |
initialRoute | ์ฑ์ ์ฒ์ ์์ํ ๋ ํ์ํ ํ์ด์ง๋ฅผ ์ค์ ํฉ๋๋ค. |
debugShowCheckedModeBanner | ๋๋ฒ๊ทธ ๋ชจ๋๋ฅผ ํ์ฑํํฉ๋๋ค. |
Scaffold
์ฑ์ ๊ธฐ๋ณธ ๊ตฌ์กฐ๋ฅผ ์ ๊ณตํ๋ ์์ ฏ
AppBar, Body, BottomNavigationBar ๋ฑ์ ํฌํจํ ์ ์์ต๋๋ค.
์์ฑ
์์ฑ | ์ค๋ช
|
appBar | ์ฑ๋ฐ๋ฅผ ์ค์ ํฉ๋๋ค. |
body | ์ฑ์ ์ฃผ์ ๋ด์ฉ์ ์ค์ ํฉ๋๋ค. |
floatingActionButton | ํ๋กํ
์ก์
๋ฒํผ์ ์ค์ ํฉ๋๋ค. |
bottomNavigationBar | ๋ฐํ
๋ค๋น๊ฒ์ด์
๋ฐ๋ฅผ ์ค์ ํฉ๋๋ค. |
tabBar | ํญ ๋ฐ๋ฅผ ์ค์ ํฉ๋๋ค. |
AppBar
์ฑ์ ์๋จ์ ํ์๋๋ ์์ ฏ
์ ๋ชฉ, ๋ฉ๋ด, ์ฑ๋ฐ ๋ฒํผ ๋ฑ์ ํฌํจํ ์ ์์ต๋๋ค.
์์ฑ
์์ฑ | ์ค๋ช
|
title | ์ฑ์ ์ ๋ชฉ์ ์ค์ ํฉ๋๋ค. |
leading | ์ฑ๋ฐ์ ์ผ์ชฝ์ ํ์๋๋ ์์ ฏ์ ์ค์ ํฉ๋๋ค. |
actions | ์ฑ๋ฐ์ ์ค๋ฅธ์ชฝ์ ํ์๋๋ ์์ ฏ์ ์ค์ ํฉ๋๋ค. |
backgroundColor | ์ฑ๋ฐ์ ๋ฐฐ๊ฒฝ์์ ์ค์ ํฉ๋๋ค. |
brightness | ์ฑ๋ฐ์ ๋ฐ๊ธฐ๋ฅผ ์ค์ ํฉ๋๋ค. |
elevation | ์ฑ๋ฐ์ ๋์ด๋ฅผ ์ค์ ํฉ๋๋ค. |
Body
์ฑ์ ์ฃผ์ ๋ด์ฉ์ ํฌํจํ๋ ์์ ฏ
์์ฑ
์์ฑ | ์ค๋ช
|
child | ์ฑ์ ์ฃผ์ ๋ด์ฉ์ ์ค์ ํฉ๋๋ค. |
BottomNavigationBar
์ฑ์ ํ๋จ์ ํ์๋๋ ์์ ฏ
:ย ์ฑ์ ํ๋จ์ ํ์๋๋ ์์ ฏ์
๋๋ค. ์ฑ์ ์ฃผ์ ๊ธฐ๋ฅ์ ๋ํ ๋ฒํผ์ ํฌํจํ ์์์ต๋๋ค.
์์ฑ
์์ฑ | ์ค๋ช
|
items | ๋ฐํ
๋ค๋น๊ฒ์ด์
๋ฐ์ ํ์๋๋ ํญ๋ชฉ์ ์ค์ ํฉ๋๋ค. |
currentIndex | ๋ฐํ
๋ค๋น๊ฒ์ด์
๋ฐ์ ํ์ฌ ํญ๋ชฉ์ ์ธ๋ฑ์ค๋ฅผ ์ค์ ํฉ๋๋ค. |
FloatingActionButton
ํ๋ฉด ์์ ๋ ์๋ ๋ฒํผ ์์ ฏ
์์ฑ
์์ฑ | ์ค๋ช
|
child | ๋ฒํผ์ ์์ด์ฝ์ด๋ ์ด๋ฏธ์ง๋ฅผ ์ค์ ํฉ๋๋ค. |
onPressed | ๋ฒํผ์ ํด๋ฆญํ์ ๋ ํธ์ถ๋๋ ํจ์๋ฅผ ์ค์ ํฉ๋๋ค. |
TabBar
ํญ์ ์ ๊ณตํ๋ ์์ ฏ
์์ฑ | ์ค๋ช
|
tabs | ํญ์ ์ค์ ํฉ๋๋ค. |
์์์ฝ๋
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
home: Scaffold(
appBar: AppBar(
title: Text('My App'),
),
body: TabBarView(
children: [
Container(color: Colors.red),
Container(color: Colors.green),
],
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
],
currentIndex: 0,
onTap: (int index) {
// ํญ์ด ๋ณ๊ฒฝ๋ ๋ ํธ์ถ๋๋ ํจ์
},
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
// ํ๋กํ
์ก์
๋ฒํผ์ด ํด๋ฆญ๋ ๋ ํธ์ถ๋๋ ํจ์
},
),
),
);
}
}
Dart
๋ณต์ฌ