μ λ ₯ μμ ―
β’
TextField
β’
Checbox
β’
Radio
β’
Switch
β’
Button
β¦
TextButton
β¦
ElevatedButton
β¦
OutlineButton
TextField
μ¬μ©μλ‘λΆν° ν
μ€νΈλ₯Ό μ
λ ₯λ°μ μ μλ μμ ―
λ¬Έλ²
TextField(
controller: TextEditingController(), // ν
μ€νΈ νλμ κ°κ³Ό μνΈ μμ©νκΈ° μν 컨νΈλ‘€λ¬ (μ΅μ
)
decoration: InputDecoration(
labelText: 'Enter your text', // ν
μ€νΈ νλμ λΌλ²¨ (μ΅μ
)
hintText: 'Type something...', // ν
μ€νΈ νλ λ΄μ ννΈλ₯Ό μ 곡 (μ΅μ
)
),
onChanged: (value) {
// ν
μ€νΈκ° λ³κ²½λ λ μ€νλλ μ½λ°± ν¨μ
},
)
Dart
볡μ¬
μμ
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('TextField Example'),
),
body: Center(
child: TextField(
controller: TextEditingController(),
decoration: InputDecoration(
labelText: 'Enter your text',
hintText: 'Type something...',
),
onChanged: (value) {
print('Text value changed: $value');
},
),
),
),
);
}
}
Dart
볡μ¬
Checbox
μ¬μ©μκ° μ ν μ¬λΆλ₯Ό λνλΌ μ μλ μμ ―
λ¬Έλ²
Checkbox(
value: true, // 체ν¬λ°μ€μ μ΄κΈ°κ° (true λλ false)
onChanged: (value) {
// 체ν¬λ°μ€μ μνκ° λ³κ²½λ λ μ€νλλ μ½λ°± ν¨μ
},
)
Dart
볡μ¬
μμ
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Checkbox Example'),
),
body: Center(
child: Checkbox(
value: true,
onChanged: (value) {
print('Checkbox value changed: $value');
},
),
),
),
);
}
}
Dart
볡μ¬
Radio
μ¬λ¬ μ΅μ
μ€ νλλ₯Ό μ νν μ μλ λΌλμ€ λ²νΌ μμ ―
λ¬Έλ²
Radio(
value: 1, // λΌλμ€ λ²νΌμ κ°
groupValue: selectedValue, // κ·Έλ£Ή λ΄μμ νμ¬ μ νλ κ°
onChanged: (value) {
// λΌλμ€ λ²νΌμ μνκ° λ³κ²½λ λ μ€νλλ μ½λ°± ν¨μ
},
)
Dart
볡μ¬
μμ
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
int selectedValue = 1;
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Radio Example'),
),
body: Center(
child: Radio(
value: 1,
groupValue: selectedValue,
onChanged: (value) {
print('Radio value changed: $value');
},
),
),
),
);
}
}
Dart
볡μ¬
Switch
μ¬μ©μκ° νΉμ μ΅μ
μ μνλ₯Ό ν κΈν μ μλ μ€μμΉ μμ ―
λ¬Έλ²
Switch(
value: true, // μ€μμΉμ μ΄κΈ°κ° (true λλ false)
onChanged: (value) {
// μ€μμΉμ μνκ° λ³κ²½λ λ μ€νλλ μ½λ°± ν¨μ
},
)
Dart
볡μ¬
μμ
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Switch Example'),
),
body: Center(
child: Switch(
value: true,
onChanged: (value) {
print('Switch value changed: $value');
},
),
),
),
);
}
}
Dart
볡μ¬
Button
β’
TextButton
β’
ElevatedButton
β’
OutlineButton
TextButton
κ°λ¨ν ν
μ€νΈ λ²νΌ
λ¬Έλ²
TextButton(
onPressed: () {
// λ²νΌμ΄ λλ Έμ λ μ€νλλ μ½λ°± ν¨μ
},
child: Text('Press me'), // λ²νΌμ νμλ ν
μ€νΈ
)
Dart
볡μ¬
μμ
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('TextButton Example'),
),
body: Center(
child: TextButton(
onPressed: () {
print('TextButton pressed');
},
child: Text('Press me'),
),
),
),
);
}
}
Dart
볡μ¬
ElevatedButton
λμ νλ©΄μμ λ μ€λ₯΄λ ν¨κ³Όλ₯Ό κ°μ§ λ²νΌ
λ¬Έλ²
ElevatedButton(
onPressed: () {
// λ²νΌμ΄ λλ Έμ λ μ€νλλ μ½λ°± ν¨μ
},
child: Text('Press me'), // λ²νΌμ νμλ ν
μ€νΈ
)
Dart
볡μ¬
μμ
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('ElevatedButton Example'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
print('ElevatedButton pressed');
},
child: Text('Press me'),
),
),
),
);
}
}
Dart
볡μ¬
OutlineButton
μΈκ³½μ μ΄ μλ λ²νΌ
λ¬Έλ²
OutlinedButton(
onPressed: () {
// λ²νΌμ΄ λλ Έμ λ μ€νλλ μ½λ°± ν¨μ
},
child: Text('Press me'), // λ²νΌμ νμλ ν
μ€νΈ
)
Dart
볡μ¬
μμ
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('OutlinedButton Example'),
),
body: Center(
child: OutlinedButton(
onPressed: () {
print('OutlinedButton pressed');
},
child: Text('Press me'),
),
),
),
);
}
}
Dart
볡μ¬