import 'package:flutter/material.dart';
void main() {
runApp(const MyApp()); //앱 처음 시작시 아래의 StatelessWidget인 MyApp을 run 한다는 것
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
//앱의 테마 데이터
//지금은 색생만 기본 색상이 blue로 설정
//다른 색깔로 바꿔서 hot reload 해보자
primarySwatch: Colors.blue,
),
//home : 표시할 화면의 인스턴스
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
//MyApp이 실제로 표시하는 StatefulWidget
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
//MyHomePage의 상태를 나타내는 클래스
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0; //화면에 표시되는 상태값인 int
//_counter를 1증가시고 상태를 갱신해주는 메소드
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
//화면의 기본 뼈대임 Scaffold
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
//화면 우측 하단에 있는 버튼
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,//클릭시 _incrementCounter 실행
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
'Flutter' 카테고리의 다른 글
Flutter - fontFamily 적용 (0) | 2022.01.02 |
---|---|
Flutter-text위젯 (0) | 2022.01.02 |
Flutter StatelessWidget , StatefulWidget (0) | 2021.12.29 |
Flutter 프로젝트 생성 (0) | 2021.12.29 |
Flutter 개발 환경 구축(windows) (0) | 2021.12.29 |