import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int num = 1;

  @override
  Widget build(BuildContext context) {
    print("빌드됨");
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("번호 : $num", style: TextStyle(fontSize: 30)),
            const MyContainer(), // new를 두번 하지 않는다.
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: (){
          num++;
          setState(() {});
          print("num : $num");
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

class MyContainer extends StatelessWidget {

  const MyContainer();

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 20,
      color: Colors.blue,
    );
  }
}