import 'package:flutter/material.dart';
import 'package:study_flutter/baseClass/BaseClass.dart';
import 'package:study_flutter/pages/HomeWidget.dart';
import 'package:study_flutter/pages/ForumWidget.dart';
import 'package:study_flutter/pages/MineWidget.dart';
class BaseTabBarextends StatefulWidget {
@override
_BaseTabBarStatecreateState() =>_BaseTabBarState();
}
class _BaseTabBarStateextends State {
intselectedIndex =0;
ListdataList;
@override
Widgetbuild(BuildContext context) {
dataList = [
{
"title" :"主页",
"norImage" :"images/index_icon1.png",
"selImage" :"images/index_icon1_selected.png",
"page" :HomeWidget(),
},
{
"title" :"论坛",
"norImage" :"images/index_icon2.png",
"selImage" :"images/index_icon2_selected.png",
"page" :ForumWidget(),
},
{
"title" :"我的",
"norImage" :"images/index_icon3.png",
"selImage" :"images/index_icon3_selected.png",
"page" :MineWidget(),
}
];
List items =List();
for(int i =0; i
var dic =dataList[i];
var item =BottomNavigationBarItem(
icon:Image.asset((selectedIndex == i) ? dic["selImage"] : dic["norImage"]),
title:Text(dic["title"]),
);
items.add(item);
}
return Scaffold(
body:dataList[selectedIndex]["page"],
bottomNavigationBar:BottomNavigationBar(
items: items,
currentIndex:selectedIndex,
selectedItemColor: BaseClass.kMainColor,
onTap: clickItem,
),
);
}
void clickItem(int index) {
setState(() {
selectedIndex = index;
});
}
}
网友评论