인프런 - 강의/플루터로 앱 만들기 고고(입문)

9 - 369게임 2

----___<<<<< 2020. 4. 21. 23:21

 

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: samuku(),
    );
  }
}

class samuku extends StatefulWidget {
  @override
  _samukuState createState() => _samukuState();
}

class _samukuState extends State<samuku> {

  int count = 0;

  void addNumber(){
    setState(() {
      count++;
      print("$count");
    });
  }

  void startAgain(){
    setState(() {
      count = 0;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              child: Text("$count", style: TextStyle(fontSize: 30.0),),
            ),
            Padding(
              padding: EdgeInsets.all(20.0),
            ),
            Container(
              child: Text(
                "짝 or 아닌 것",
                style: TextStyle(fontSize: 80.0, color: Colors.red),
              ),
            ),
            Padding(
              padding: EdgeInsets.all(20.0),
            ),
            Container(
              child: RaisedButton(
                color: Colors.red,
                child: Text("자, 게임을 시작하지"),
                onPressed: addNumber,
              ),
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Text("초기화"),
        onPressed: startAgain,
      ),
    );
  }
}

 

 

'인프런 - 강의 > 플루터로 앱 만들기 고고(입문)' 카테고리의 다른 글

11 - 커플게임 1  (0) 2020.04.22
10 - 369게임 3  (0) 2020.04.22
8 - 369 게임  (0) 2020.04.20
7 - Image insert  (0) 2020.04.20
6 - show hide  (0) 2020.04.20