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

14 - 커플게임 4

----___<<<<< 2020. 4. 24. 00:36

 

 

 

import 'package:flutter/material.dart';
import 'package:flutterapp1231244444/Tab_three.dart';

import 'Tab_one.dart';
import 'Tab_two.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {

  int tab_number = 0;

  List<Widget>_widgets = <Widget>[
    TabOne(),
    TabTwo(),
    TabThree(),
  ];

  void _onItemTapped(int index){
    print(index);
    setState(() {
      tab_number = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: _widgets.elementAt(tab_number),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.image, color: Colors.red,),
            title:Text("레벨1", style: TextStyle(color:Colors.red),)
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.image, color: Colors.pink,),
              title:Text("레벨2", style: TextStyle(color:Colors.pink),)
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.image, color:Colors.green),
              title:Text("레벨3", style: TextStyle(color:Colors.green),)
          ),
        ],
        currentIndex: tab_number,
        onTap: _onItemTapped,
      ),
    );
  }
}
import 'dart:math';

import 'package:flutter/material.dart';

class TabOne extends StatefulWidget {
  @override
  _TabOneState createState() => _TabOneState();
}

class _TabOneState extends State<TabOne> {

  String text = "게임 시작해보세요!";

  var list = [
    "머리 쓰다듬어주기",
    "귀 만져주기",
    "어깨 주물러주기",
    "다리 주물러주기",
    "심부름 해주기"
  ];

  Random random = Random();

  void changeText(){
    setState(() {
      text = list[random.nextInt(list.length)];
      print(list[random.nextInt(list.length)]);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.red,
      body : Center(
        child: Text(text,
          style: TextStyle(
            fontSize: 40.0
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.info),
        onPressed: changeText,
      ),
    );
  }
}

 

 

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

16 - My 아이돌 앱 2  (0) 2020.04.27
15 - My 아이돌 앱  (0) 2020.04.27
13 - 커플게임 3  (0) 2020.04.24
12 - 커플게임 2  (0) 2020.04.23
11 - 커플게임 1  (0) 2020.04.22