Open name27 opened 1 year ago
// ignore_for_file: prefer_const_constructors
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String message = '안녕';
int level = 1;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Column(
children: [
Text(message),
InkWell(
onTap: () {
level ++;
setState(() {}); //이 함수를 넣어줘야 재 빌드 됨
},
child: Text('$level레벨 입니다.')
),
],
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
message = '반가워';
setState(() {});
},
label: Icon(Icons.change_circle)
),
),
);
}
}
Flutter는 그림을 그리는 툴이고 그것을 빌드라고 한다. 모든 위젯은 빌드를 통해 그려진다
Widget build(BuildContext context) {}
로 빌드가 진행 됨 Flutter 위젯은 Stateless 위젯, Stateful 위젯 둘 중 하나이다. StatelessStateful