
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wallpaper/pages/downloadpage/downloadpage_view.dart';
import 'package:wallpaper/pages/homePage/homePage_view.dart';
import 'package:wallpaper/pages/collectionpage/collectionpage_view.dart';
import 'package:wallpaper/pages/mypage/mypage_view.dart';

import 'tabarpage_controller.dart';

class TabbarPageView extends GetView  <TabbarPageController>{
   const TabbarPageView({super.key});

  @override 
  Widget build(BuildContext context) {
    final List<Widget> childPageList = getPages();
    final List<BottomNavigationBarItem> listBarItems = getTabarItem();
    return Scaffold(
      bottomNavigationBar:Obx(() => BottomNavigationBar(
        items: listBarItems,
        iconSize: 30,
        type: BottomNavigationBarType.fixed,
        selectedFontSize: 14,
        unselectedFontSize: 14,
        currentIndex: controller.currentIdenx.value,
        onTap: controller.onItemTapped,
      )),
      body: Obx(() => childPageList[controller.currentIdenx.value],) 
    );
  }

//初始化地步tabbar的选项
  List<BottomNavigationBarItem> getTabarItem(){
    return [ const BottomNavigationBarItem(
          icon: Icon(Icons.home),
          label: "Home"
      ),
      const BottomNavigationBarItem(
        icon: Icon(Icons.download),
        label: "下载"
      ),
      const BottomNavigationBarItem(
        icon: Icon(Icons.person),
      label: "我的"
      ),
    ];
  }

  //返回每个tabitem对应控制器视图,必须一一对应
  List<Widget> getPages(){
    return [const HomePageView(), DownloadPageView(),const MyPageView(),];
  }


}