์๋ ํ์ธ์! ์ค๋์ Flutter์์ ์์ฃผ ์ฌ์ฉ๋๋ ๋ฒํผ ์์ ฏ์ธ TextButton, ElevatedButton, OutlinedButton์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค. ์ด ๊ธ์์๋ ํด๋น ์์ ฏ๋ค์ ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ๊ณผ ์์ ์ฝ๋๋ฅผ ์ ๊ณตํฉ๋๋ค. ๋ํ, ์ฝ๋ ์์ฑ ์ ์ฃผ์ํด์ผ ํ ๋ช ๊ฐ์ง ํ๋ฌํฐ ๊ท์น๊ณผ ์ ์ฉํ ์ฝ๋ ์ ๋ฆฌ ๋จ์ถํค๋ ํจ๊ป ์์๋ด ์๋ค.
Button
- TextButton
TextButton์ ๊ฐ๋จํ ํ ์คํธ ๋ฒํผ์ ๋ง๋ค ๋ ์ฌ์ฉ๋ฉ๋๋ค. ์๋๋ TextButton์ ์์ฑํ๊ณ ๊ทธ์ ๋ํ ์์ ์ฝ๋์ ๋๋ค.
TextButton(
onPressed: () {
// ๋ฒํผ ํด๋ฆญ ์ ์คํํ ๋์
print('TextButton ํด๋ฆญ๋จ');
},
child: Text('TextButton ํ
์คํธ'),
)
- ElevatedButton
ElevatedButton์ ์ผ๋ฐ์ ์ธ ๋์ด๋ฅผ ๊ฐ์ง ๋ฏธ๋ฆฌ ์ ์๋ ๋ฒํผ ์คํ์ผ์ ์ฌ์ฉํ ๋ ์ ์ฉํฉ๋๋ค. ๋ค์์ ElevatedButton์ ์์ ์ฝ๋์ ๋๋ค.
ElevatedButton(
onPressed: () {
// ๋ฒํผ ํด๋ฆญ ์ ์คํํ ๋์
print('ElevatedButton ํด๋ฆญ๋จ');
},
child: Text('ElevatedButton ํ
์คํธ'),
)
- OutlinedButton
OutlinedButton์ ์ธ๊ณฝ์ ์ด ์๋ ๋ฒํผ์ ๋ง๋ค ๋ ์ฌ์ฉ๋ฉ๋๋ค. ์๋๋ OutlinedButton์ ์์ ์ฝ๋์ ๋๋ค.
OutlinedButton(
onPressed: () {
// ๋ฒํผ ํด๋ฆญ ์ ์คํํ ๋์
print('OutlinedButton ํด๋ฆญ๋จ');
},
child: Text('OutlinedButton ํ
์คํธ'),
)
์ฌ์ฉํ ์๋ ๋ค์ ์๋ ์ฝ๋๋ฅผ ํตํด์ ํ์ธ ๊ฐ๋ฅํฉ๋๋ค.
ํ์ผ : main.dart
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
// appBar ์์ ๋ณ๊ฒฝ
appBarTheme: AppBarTheme(
backgroundColor: Colors.blue, // appBar ์ ์ฒด ์์ ํ๋์
titleTextStyle: TextStyle(
color: Colors.black,
fontSize: 25.0, // ํฐํธ ์ฌ์ด์ฆ ๊ธฐ๋ณธ ์ฌ์ด์ฆ์ 2.5๋ฐฐ
), // title ํ
์คํธ ์์ ๊ฒ์ ์
)),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int count = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('$count',
style: TextStyle(
color: Colors.black,
fontSize: 100,
)),
Text('$count',
style: TextStyle(
color: Colors.red,
fontSize: 70,
)),
ElevatedButton(
onPressed: () {
print('ElevatedButton');
},
child: Text('ElevatedButton'),
),
TextButton(
onPressed: () {
print('TextButton');
},
child: Text('TextButton'),
),
OutlinedButton(
onPressed: () {
print('OutlinedButton');
},
child: Text('TextButton'),
)
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// ํ๋ฉด ๊ฐฑ์
setState(() {
count++;
});
},
child: Icon(Icons.add_box_outlined)),
);
}
}
์ฝ๋ ์ ๋ฆฌ ๋จ์ถํค
- 'Command' + 'Alt' + 'l'
ํ๋ฌํฐ ๊ท์น
- ํ๋์ ํ๋ฉด์ ํ๋์ ํ์ผ์ ๋ง๋ค์ด์ผ ํ๋ค.
- ๋ณ์๋ ํญ์ ์๋ฌธ์๋ก ์์ํด์ผํ๋ค.(๋ณ์, ๋ฉ์๋, ํจ์)
- ํด๋์ค๋ ํญ์ ๋๋ฌธ์๋ก ์์ํ๋ค.
[ํ์ผ๋ช ๋ค์ด๋ฐ ๊ท์น] ํ๋ฌํฐ ์๋ก์ด ํ์ผ ๋ง๋ค๋ ๊ท์น
- CamelCase๋ก ์์ฑ๋์๋ ๋ถ๋ถ์ ๋ช ์นญ์ snake_case๋ก ๋ฐ๊ฟ์ ์ ์ฅํด์ผํจ!!
import ํธํ๊ฒ ํ๊ธฐ
- ๋นจ๊ฐ์ ๋ฐ์ค ์๋ ๋ถ๋ถ์์ option + enter ํค ๋๋ฌ์ ๋ถ๋ฌ์ค๊ณ , ์ ๋ ๊ฒฝ๋ก ์ฌ์ฉํ๊ธฐ
๋ค์ด๋ฐ ์ผ๊ด ๋ณ๊ฒฝ
- 'Shift' + 'f6' ๋ฒํผ์ผ๋ก ํ๋ฒ์ ์์ ์ด ๊ฐ๋ฅํ๊ณ
- ์ฐํด๋ฆญํ์ฌ Refactor์์ ์์ ์ด ๊ฐ๋ฅํ๋ค.
- ํ๋ฒ ์์ ํ๋ฉด ๋ชจ๋ ์ฝ๋, ๋ชจ๋ ํ์ผ์์ ๋์ผํ๊ฒ ์์ ๋๋ ์์ฒญ๋ ๊ธฐ๋ฅ์ด๋ค!!
ํ์ฌ ์ฌ์ฉํ๊ณ ์๋ ๋ณ์๊ฐ ๋ค๋ฅธ ํ์ผ์์ ์ด๋ค ์์ผ๋ก ์ฌ์ฉ๋๊ณ ์๋์ง ๋ณด๋ ๋ฒ
- 'Command' + 'b'
์ต๊ทผ์ ์ฌ์ฉํ๋ ํ์ผ ์ด๊ธฐ
- 'Command' + 'e'
pubspec.yaml ํ์ผ์ ์์ ํ์๋
- ์ฐ์ธก ์๋จ 'Pub get' ๊ผญ ๋๋ฌ์ฃผ๊ธฐ
- ํ๊ฒฝ ์ธํ ํ ์ดํ์ ์ธํ ์ ๋ฐ์ํด์ฃผ๊ธฐ ์ํด์๋ ๋ฒํผ์ ๋๋ฌ์ค์ผ ํ๋ค
์ด๋ฏธ์ง ํํํ๊ธฐ
- image.network ๋ฐฉ์
- ํ์ผ์ ์ ์ฅํด์ ๋ถ๋ฌ์ค๋ ๋ฐฉ์ - yaml ํ์ผ์ ๊ฐ์ ์์ ํด์ค์ผ ํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์กด์ฌํจ
Container
- ์๊น๊ณผ ํฌ๊ธฐ๋ฅผ ๊ฐ์ง ์ ์์
- ์์(child)๋ ๋ถ๋ชจ ์์ฑ์ ๋ฐ๋ผ๊ฐ๋ ์ฑํฅ์ด ์์
์ด๋ ๊ฒ ์คํํ๋ฉด ์๋์ ๊ฐ์ด ์์์ ๊ทธ๋ฆผ ์ฌ์ด์ฆ๊ฐ 120 120์ด ๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค. 100 100 ์ฌ์ด์ฆ๊ฐ ์๋๋ผ.
- ๋ณดํต ์ด๋ฐ ๊ฒฝ์ฐ์ padding ์ผ๋ก ๊ฐ์ธ๋ ์ฝ๋๋ฅผ ์์ฑ์ ๋ง์ด ํ๊ฒ ๋๋๋ฐ
์ฝ๋๋ ์๋์ ๊ฐ์ด ์์ฑํ ์ ์๊ณ , ์ด๋ ํ๋ฉด์ ๋ค์๊ณผ ๊ฐ์ด ๋ณด์ฌ์ง๊ฒ ๋๋ค.
์ฌ์ง ์๋
'๐๏ธ์ํํธ์จ์ด > Flutter' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Flutter] Dart์์ static ์ญํ ๊ณผ ๋ฉ๋ชจ๋ฆฌ ํ ๋น (0) | 2024.05.11 |
---|---|
Flutter Wrap ์์ ฏ ์ฌ์ฉ ํ: option(โฅ)+enter ๋จ์ถํค ํ์ฉํ๊ธฐ (0) | 2023.10.01 |