<< 소스 코드 >>
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
//stateless widget이라서 화면에 counter가 올라가지 않음
//ctrl + s 눌러 저장 시 변경된 counter 값이 화면에 반영됨.
class MyApp extends StatelessWidget {
int counter = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//화면에 문구와 counter 변수값 출력
Text('You have pushed the button this many times:'),
Text(
'$counter',
style: Theme.of(context).textTheme.displayLarge,
)
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
//버튼 클릭 시 counter 변수 값. 증가
onPressed: (){
counter++;
print("$counter");
},
),
),
);
}
}
<< 출력 화면 >>
'Flutter (with 코딩셰프)' 카테고리의 다른 글
[2023.12.12] 플러터(flutter) 조금 매운맛 강좌 03 | 로그인과 주사위게임 (0) | 2023.12.12 |
---|---|
[2023.12.08] 플러터(flutter) 조금 매운맛 강좌 02 | Sateful Widget #2 (0) | 2023.12.08 |
[2023.12.01] 플러터(flutter) 순한 맛 강좌 27 | Buttons (0) | 2023.12.01 |
[2023.11.30] 플러터(flutter) 순한 맛 강좌 26 | ScaffoldMessenger (0) | 2023.11.30 |
[2023.11.29] 플러터(flutter) 순한 맛 강좌 24 | Collection & Generic (0) | 2023.11.29 |