will-play/lib/Tab.dart

154 lines
4.2 KiB
Dart

// ignore_for_file: prefer_const_constructors, duplicate_ignore
import 'package:flutter/material.dart';
import 'views/home/Home.dart';
import 'views/party/Party.dart';
import 'views/discover/Discover.dart';
import 'views/information/Information.dart';
import 'views/mine/Mine.dart';
class Tabs extends StatefulWidget {
final int? index;
Tabs({Key? key, this.index = 0}) : super(key: key);
@override
State<Tabs> createState() => _TabsState(this.index);
}
class _TabsState extends State<Tabs> {
int _currentIndex = 0;
List list = [
HomePage(),
PartyPage(),
DiscoverPage(),
InformationPage(),
MinePage()
];
_TabsState(index) {
this._currentIndex = index;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: this.list[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: this._currentIndex, //选中的索引值
iconSize: 36.0, //icon的大小
fixedColor: Color.fromRGBO(21, 185, 208, 1), //选中的颜色
type: BottomNavigationBarType.fixed, //配置底部tabs可以有多个按钮
onTap: (int index) {
setState(() {
this._currentIndex = index;
});
},
items: [
BottomNavigationBarItem(
icon: Image.asset(
"images/tabs/home_no.png",
width: 20.0,
height: 20.0,
),
activeIcon: Image.asset(
"images/tabs/home_active.png",
width: 20.0,
height: 20.0,
),
// icon: Icon(Icons.home),
label: "首页",
),
BottomNavigationBarItem(
icon: Image.asset(
"images/tabs/party_no.png",
width: 20.0,
height: 20.0,
),
activeIcon: Image.asset(
"images/tabs/party_active.png",
width: 20.0,
height: 20.0,
),
label: "派对",
),
BottomNavigationBarItem(
icon: Image.asset(
"images/tabs/information_no.png",
width: 20.0,
height: 20.0,
),
activeIcon: Image.asset(
"images/tabs/information_active.png",
width: 20.0,
height: 20.0,
),
label: "消息",
),
BottomNavigationBarItem(
icon: Image.asset(
"images/tabs/discover_no.png",
width: 20.0,
height: 20.0,
),
activeIcon: Image.asset(
"images/tabs/discover_active.png",
width: 20.0,
height: 20.0,
),
label: "发现",
),
BottomNavigationBarItem(
icon: Image.asset(
"images/tabs/mine_no.png",
width: 20.0,
height: 20.0,
),
activeIcon: Image.asset(
"images/tabs/mine_active.png",
width: 20.0,
height: 20.0,
),
label: "我的",
)
],
),
drawer: Drawer(
child: Column(
children: [
Row(
children: [
Expanded(
child: DrawerHeader(
child: Text("Drawer组件"),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://www.itying.com/images/flutter/2.png'),
fit: BoxFit.cover),
),
),
)
],
),
ListTile(
title: Text('我的空间'),
leading: Icon(Icons.home),
),
ListTile(
title: Text('设置'),
leading: Icon(Icons.settings),
onTap: () {
Navigator.of(context).pop(); //隐藏侧边栏
Navigator.of(context).pushNamed('/routeParms');
},
)
],
),
),
endDrawer: Drawer(
child: Text('右侧抽屉'),
),
);
}
}