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

12 - 커플게임 2

----___<<<<< 2020. 4. 23. 17:22

탭 만들기!!

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),
            title:Text("레벨1")
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.image),
              title:Text("레벨2")
          ),
          BottomNavigationBarItem(
              icon: Icon(Icons.image),
              title:Text("레벨3")
          ),
        ],
        currentIndex: tab_number,
        onTap: _onItemTapped,
      ),
    );
  }
}

 

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

14 - 커플게임 4  (0) 2020.04.24
13 - 커플게임 3  (0) 2020.04.24
11 - 커플게임 1  (0) 2020.04.22
10 - 369게임 3  (0) 2020.04.22
9 - 369게임 2  (0) 2020.04.21