import 'package:flutter/material.dart';
import 'home.dart';
import 'search.dart';
class MyBottomNavigationBar extends StatefulWidget {
final int index;
MyBottomNavigationBar({this.index = 0});
@override
_MyBottomNavigationBarState createState() =>
_MyBottomNavigationBarState(this.index);
}
class _MyBottomNavigationBarState extends State<MyBottomNavigationBar> {
_MyBottomNavigationBarState(index) {
this._currentIndex = index;
}
int _currentIndex = 0;
List _pageList = [
HomePage(),
SearchPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hello Flutter'),
),
body: this._pageList[this._currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (int index) {
setState(() {
this._currentIndex = index;
});
},
// iconSize: 20,
// fixedColor: Colors.pink,
type: BottomNavigationBarType.fixed, // 配置多个tabItem
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: '首页',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: '搜索',
),
],
),
// Drawer
drawer: Drawer(
// child: DrawerHeader(child: Text('DrawerHeader')),
child: UserAccountsDrawerHeader(
accountName: Text('lynn'),
accountEmail: Text('lynn@163.com'),
otherAccountsPictures: [
Image.network('https://images.pexels.com/photos/6922718/pexels-photo-6922718.jpeg?cs=srgb&dl=pexels-kira-schwarz-6922718.jpg&fm=jpg')
],
),
),
);
}
}