Flutter - Button 위젯
2023. 3. 4. 13:47ㆍFlutter/기본 위젯
ElevatedButton
-배경색을 가진 일반적인 버튼
-onPressed() 하수에 원하는 액션 지정 가능
OutlinedButton
-배경이 투명하고 외곽선을 가진 버튼
TextButton
-텍스트를 사용한 심플한 버튼
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 const MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Flutter'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title,),
),
body: Center(
child: Column(
children: [
SizedBox(
width: 200,
height: 50,
child: ElevatedButton(
onPressed: () {},
child: Text(widget.title),
),
),
SizedBox(
width: 200,
height: 50,
child: OutlinedButton(
onPressed: () {},
child: Text(widget.title),
),
),
SizedBox(
width: 200,
height: 50,
child: TextButton(
onPressed: () {},
child: Text(widget.title),
),
),
FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
print("Clicked");
},
)
],
)),
);
}
}
'Flutter > 기본 위젯' 카테고리의 다른 글
Flutter - ListView, ListTile 위젯 (0) | 2023.03.04 |
---|---|
Flutter - SingleChildScrollView 위젯 (0) | 2023.03.04 |
Flutter - Expanded 위젯 (0) | 2023.03.04 |
Flutter - Container 위젯 (0) | 2023.03.02 |